Muhammad Asfund Muhammad Asfund - 1 year ago 67
PHP Question

How to Call/Use Controller Method in its View using Laravel 5.0

Hello All and thanks to all in advance.

I need to use my controller function in its own view.

Please help me out.

I have tried Facade but failed.

Answer Source

You want to use a function defined in a Controller in one of the views it is calling?

If that's your question you can do following, (I am assuming the function is public static function returning some string). In your blade view file you can just call the function using the full name space path.


(There are ways in blade to import a class using use statement)

It is not recommended to call functions defined in controller like this (its against MVC), you can define them in the Model or create a separate Helper class.