dimanche 4 octobre 2015

Laravel 5.1 - View variables for a controller

What I wanna do is to know, inside a view, if I'm in a specific controller or not. From what I know, I've got two choices and I don't have the answer to either of them :-D

  • inject a view variable using the share method in my AppServiceProvider, which involves getting the current controller name(or at least the action name so that I can switch it) inside the service provider.

  • inject a variable to all the views returned in the controller. For example does controllers have a boot method? Or can I override the view() method in the following code snippet?

    public function someAction(Request $request) { return view('someview', ['myvar' => $myvalue]); }

  • well of course there's the easy (yet not easy :|) solution: add the variable in all methods of the controller. I don't like this one.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire