How laravel post redirection works? - laravel

I have some confusion in laravel post method redirection.
I have to post data from form. Once the data has been post, I have to retrieve the data and store it into the db and get some data related to the post data and pass the data to laravel.
Here, I have used the redirect() function to redirect to the particular route.
When I redirect with data mean it not get the data only way to use the session to get the data
I mean push the data in session and then retrieve in view.
how to pass the data to another view when post method ?

you can use with() method of laravel to send the data to another view as
return Redirect::route('your_redirect_url')->with('data' => $data);
But it will also store data in the session only, so you can access it as
Session::get('data')

Related

I want to create routes from database Data in Laravel

I want to retrieve data from the database and create the dynamic route.
For example, in Laravel web route file we write :
Route::get('/{slug}', function($slug){
return $slug;
});
So, I want to create this code after retrieving data from the database. and based on the data I can create the dynamic route with params or passing model data to the view.
And also how do I create dynamic view files. Like for different layout or from the database data.
Thanks in Advance.

defining routes with parameters in laravel

in Laravel i want to do a page with a search box and a form (the route could be /products)
I want to retrieve information using search box typing id from a db and populate the form.
I request datas with the route for example /products/{id}
But in the controller i use the same function products($Request request) with if the id exists do something if no do other things, or there are two different functions?
Thx
Please go through the Laravel Resource Controllers.
To show list of products i.e. /products, create a index() method. To show a specific product i.e. /product/{id}, create show() method.
Probably is better use the same function, if id exist, return the page with the values filling the form, if not returns the same page but with a message showing that product doesn't exist

Access tables names in middleware in a single transaction

Let's say CRUD operations are performed on three tables in a single controller method.
Is it possible for me to get all the tables names on which CRUD operations are performed in the middleware.
As of now, when I submit a form I can only access those inputs from the request in the middleware, but when I insert three records into three different tables in a single controller action am not able to access the table names in the middleware.
Any help is much appreciated.
I don't think that it is possible to get table name automatically. You will have to right custom logic in middleware for that controller action. Because the response object we get in middleware after the execution of controller method is html, json, etc response which is to be sent to client.

Keep filter data in laravel

I have a page with table of some data (let's say posts). I have a form there which leads to the same page but with get parameters. So when I choose December in dropdown list form will lead to posts/index?month=december. Controller index method makes eloquent query using query string parameters to filter rows. After that I click edit post(or add new post) and change something through edit form. Then update or store method redirects back to index as usually. What is the best way to come back to index?month=december page? Sessions? How should I do it? Set some values from query to session in Controller index method when I come there first time and get them also in Controller method from session after editing/creating?
Try to append all request parameters in the redirect:
return redirect()->route('route_name',['month' => request()->get('month')]);
You can read more about this in this section in the docs.

How to pass an array to controler from view ??

Hi guys I have an array that is created in my View side and I want to pass it to a contoller so I can insert it in to my database.. I have seen examples that use json encode and decoding but how do i apply this to my laravel 5 project ?
That depends on your controller code. However, one way for that is to pass them as query parameters.
Link

Resources