The only way you can send data through a redirect is by adding it to the querystring
Session persists through page refresh - otherwise there would not be a lot of point in it. Think about sites that persist a shopping basket for instance.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to send the data throught redirect.
I know I can send it through session but when the page refreshes it will get lost.
So a good way of sending data thorugh redirect is???
The only way you can send data through a redirect is by adding it to the querystring
Session persists through page refresh - otherwise there would not be a lot of point in it. Think about sites that persist a shopping basket for instance.
@snapey I didn't get the point you are talking about..
If you want to 'send' a variable to another page with redirect;
/myotherroute?data=fred&moredata=doe
or
put the data in session.
but when the page refreshes it will get lost.
Wrong
/myotherroute?data=fred&moredata=doe this method seems good to mee
In my first controller I store the data and redirect to the 'questions' like this and $id is the parameter i want to send..
return redirect()->route('questions', ['id' => $id]);
In my web.php
Route::get('/questions/{$id}', 'QuestionsController@id')->name('questions');
In my QuestionsController,
public function id($id) {
echo $id;
}
I also get the url
http://127.0.0.1:8000/questions/2
But It always says page not found... why??
You can return view and send data with it.
@nnnayeem I don't want to use view because the next view i want to pass will have the same route
https://laravel.com/docs/5.6/redirects#redirecting-named-routes
I was following this documentation.
It should have performed according to the documentation..
Do you have another route named "questions" ?
Or that I have an url similar to "/questions/" ?
@Vilfago This is all my routes
Route::get('/', function () {
return view('index');
});
Route::post('/submit_survey', 'SurveysController@store'- >name('submit_survey');
Route::get('/submit_survey', 'SurveysController@index')->name('submit_survey');
Route::post('/submit_categories', 'CategoriesController@store')->name('submit_categories');
Route::get('/submit_categories', 'CategoriesController@index')->name('submit_categories');
Route::get('/questions/{$id}', 'QuestionsController@id')->name('questions');
Route::post('/submit_no_of_questions', 'CountQuestionsController@store')->name('submit_no_of_questions');
Route::get('/submit_no_of_questions', 'CountQuestionsController@index')->name('submit_no_of_questions');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
remove the $ from id in the route
not Route::get('/questions/{$id} but instead Route::get('/questions/{id}
@snapey thank you
Please or to participate in this conversation.