you can create a function that have those lines in helperController and to access it my this link help you
Oct 2, 2019
2
Level 1
Code Block
Hello All,
I have a question regarding the use of the same 9 lines of code throughout many controller functions and the best practice for this with regards to Laravel.
We are building out an internal tool which interacts with Microsoft Navision and to consume some of its data through ODATA I use the same 9 lines of code repeatedly with only preset variables which change.
$login = $this->odataLogin;
$password = $this->odataPass;
$url = $this->odataBaseURL."Customer_List?$format=json&$filter=No%20eq%20'$nav_cNumber'";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);
$obj = new \stdClass();
$obj = json_decode($result, true);
Is there a way to call this into multiple controllers and functions more effectively?
Thanks,
Level 1
Please or to participate in this conversation.