Posts

Showing posts from October, 2019

Get environment value in controller

Step 1.)  Add your variable to your  .env  file, ie. EXAMPLE_URL = "http://google.com" Step 2.)  Create a new file inside of the  config  folder, any name, ie. config / example . php Step 3.)  Inside of this new file, I add an array being returned, containing that env variable. <? php return [ 'url' => env ( 'EXAMPLE_URL' ) ]; Step 4.)  Because I named it "example" my configuration 'namespace' is now an example. So now, in my controller I can access this variable with: $url = \config ( 'example.url' ); Example public static function mail ( $param ) { //$_ENV['yourkeyhere']; $mailgunsecret = env ( 'MAILGUN_SECRET' ); $mailguurl = env ( 'MAILGUN_DOMAIN' ); } $data = array(             "MAIL_DRIVER" => env('MAIL_DRIVER'),             "MAIL_HOST" => env('MAIL_HOST'),             "MAIL_PORT" => en...

json_encode() escaping forward slashes

I'm pulling JSON from Instagram: $instagrams = json_decode($response)->data; Then parsing variables into a PHP array to restructure the data, then re-encoding and caching the file: file_put_contents($cache,json_encode($results)); When I open the cache file all my forward slashes "/" are being escaped: http:\/\/distilleryimage4.instagram.com\/410e7... I gather from my searches that  json_encode()  automatically does this...is there a way to disable it? Yes, you only need to use the  JSON_UNESCAPED_SLASHES  flag. json_encode ( $str , JSON_UNESCAPED_SLASHES ); Example Demo $data = array ( "app_name" => env( 'APP_NAME' ), "queue" => 'update-order' , "payload" => [ "entity_id" => $entity_id , "order_id" => $request [ 'order_id' ], "delivery_date" => $orderDate [ 0 ]-> order_delivery_date , ...