Laravel

How to send data from controller to view laravel

Controller to view pass data in laravel

When we are working with web applications we need to use queries, insert, update, delete, select manipulation. So we need to pass the data’s to Controller as well as from controller to view. Laravel providing default way to pass data to view. By using with() keyword we can send the data’s. Here we are goint to discuss to how to pass data from controller to view.

Before Going that we will discuss How to store global varibale in controller for view files.

Possible ways to send data to view :

1. Passing an array :-

 2. Working with query :- with with()



2.1 with compact() :-

 3. Passing select options :-

Above code works with view::make() now we will see pass data from controller to view on redirect. it’s also easy to pass data on redirect in laravel. Let’s see how to pass data from controller on redirect.

1. Redirect with flash data :-

return Redirect::to(‘user/login’)->with(‘message’, ‘Login Failed’);
2. Redirect to named route with data :-

return Redirect::route(‘profile’, array(‘user’ => 1));
For More information follow official Documentation Views & Responses Laravel

Thanks!. If you like this article don’t forget to share and comment.