1

What is the difference between,

return View::make('hello');

and

return view('hello');

and

return 'hello';

they all produce the same output but why three syntaxes?

1 Answer 1

1

Actually, Your examples are a bit different.

view() is just a helper function operating just like View::make(). But doing it this way, you don't have to use View; at top of your controller (or service class) in that manner. Behind the scenes Laravel would make a view instance and populate it with the arguments that is just passed in. In your example, hello.blade.php.

Returning 'hello' is somewhat different because there is no blade file involved and the passed string is passed to the Response object directly.

Check out these links, especially the api. It can be very helpful.

https://laravel.com/docs/5.1/helpers#method-view

https://laravel.com/api/5.1/Illuminate/View/View.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.