Skip to content
Advertisement

Laravel Redirecting to a route is not working?

I am new to Laravel, when I am using redirect()->route(‘route_name’) after saving data, it does not work.

Here is my controller function:

public function store_layouts(Request $data){
        $layout = new point_prizes();
        $layout->name = $data->name;
        $layout->points = $data->points;
        $layout->prize = $data->price;
        $layout->timestamps = false;
        $layout->save();

        redirect()->route('view_layouts');
    }

Here are my routes :

Route::get('/admin/layouts' , 'AdminController@view_layouts')->name('view_layouts');
Route::get('/admin/layouts/make' , 'AdminController@create_layouts')->name('create_layouts');
Route::post('/admin/layouts/store' , 'AdminController@store_layouts')->name('store_layouts');

Any help will be appreciated.

Advertisement

Answer

You need to add the return keyword

return redirect()->route('view_layouts');
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement