Sent All Variables in Controller Function to the View
Ad
I have a function in my controller. I created a lot of variables, and send them to my view via compact
function one by one.
public function edit($id,$cpe_mac) {
$vcpe = VSE::vcpe($cpe_mac);
$vcpe = json_decode (json_encode($vcpe), FALSE);
$cpe = VSE::cpe($cpe_mac);
$wan = $cpe['wan'];
$acl = $cpe['acl'];
$guest = $cpe['vlan'][0];
$private = $cpe['vlan'][1];
$cpe_name = VSE::cpe_name($cpe_mac)['cpe_name'];
$p_max_up = $private['bandwidth']['max_up'];
$p_max_down = $private['bandwidth']['max_down'];
$p_ip = $private['lan']['ip_address'];
$p_netmask = $private['lan']['netmask'];
$p_max_clients = $private['lan']['dhcp_server']['max_clients'];
$p_dns = $private['lan']['dhcp_server']['dns'][0];
$p_dns2 = $private['lan']['dhcp_server']['dns'][1];
$cpe = json_decode (json_encode($cpe), FALSE);
return view('cpe.edit', compact(['vcpe','cpe_mac','cpe_name','cpe','wan','acl','private','guest',
'p_max_up','p_max_down','p_ip','p_netmask','p_max_clients','p_dns','p_dns2'
]));
}
Question
Is there a way to send all the variables to the view rather than doing it one by one ?
Ad
Answer
Ad
You could do the following...
return view('cpe.edit', get_defined_vars());
There might be some unnecessary overhead though if you are creating a lot of variables which you would not otherwise need in your view.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad