php - Using functions within a Laravel controller -


i have standard laravel controller function on 350 lines of logic number of different on-page elements. of logic taken out put within it's own function need pass variables laravel controller used within view.

does laravel recommend standards this? or can create function within controller , pass final variables in php?

example of current controller, split logic here own function , return values new function getindex() function.

class pubscontroller extends controller {     public function getindex()     {         //date helpers         $datethismonth = carbon::now()->startofmonth()->todatestring();         $datelastmonth = carbon::now()->submonth()->startofmonth()->todatestring();         $datenextmonth = carbon::now()->addmonth()->startofmonth()->todatestring();     } } 

controllers php class, can use functions within them same other class. example, if have line of logic calculates total before passing index view, this:

public function index(){      $total = $this->calculatetotal($a, $b);     return view("index")->with(["total" => $total]); }  public function calculatetotal($a, $b){     return $a + $b; } 

$this within controller can access properties or functions within controller, you're free define helper functions , access them accordingly.

hope helps!


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -