i want make "rule" for all functions in my controller. Example - in my AdminController i want this function(down) work for all functions without having to write it in every new function.
if(session('Admin')) {
$accinfo = DB::Table('MEMB_INFO')->count();
$charinfo = DB::Table('Character')->count();
return view('ap.home', ['accinfo' => $accinfo, 'charinfo' => $charinfo]);
}
else
{
return redirect('adminpanel/login');
}`
CodePudding user response:
Simply, you can use middleware and use it in the constructor method for the relevant controller.
You can also browse Traits if you want to include a specific code block in the controller by simply saying use it.
Or, you can create a helper file according to your needs and call the relevant functions from there.