How to make a redirect to Laravel on the route? I tried this:

return redirect()->route('add') 

It gives an error that there is no such route. But he is.

 Route::get('/add', function (){ $model = new getInfoController(); $category = $model->getCategory(); $product = $model->getProduct(); return view('admin/addCategory', compact("category","product")); }); 

    1 answer 1

    Enter the name of the route and it will work.

     Route::get('/add', function (){ $model = new getInfoController(); $category = $model->getCategory(); $product = $model->getProduct(); return view('admin/addCategory', compact("category","product")); })->name('add'); 
    • Thank you very much. I miscalculated in the documentation of this moment) - Andrei