After data from a form is saved i wanted to get back to the admin page.
I checked the database and the new data was there but I got an error:
"Route [pages.admin] not defined."
My Admin Controller code:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesValidator;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesAuth;
use AppModelsAdmin;
class AdminController extends Controller
public function store(Request $request)
{
// Validation code
// Saveing code
return redirect()->route('pages.admin')
->with('success', 'Admins created successfully.');
}
My Page Controller:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class PagesController extends Controllerpublic
function admin(){
return view('pages.admin');
}
Routes:
Route::get('/admin', 'PagesController@admin');
Route::post('admin_form', 'AdminController@store');
Would appreciate the help.
I looked in online sources but it didn’t help
2
Answers
I found a video and changed my code in the controller to
and it worked.
You are confusing the name of a view with the name of a route. Your view has the name
pages.admin
because there is aadmin.blade.php
view in thepages
folder within theviews
folder of your application.For
route('pages.admin')
to work, you need to assign a name to a route. You may do this by usingname()
when defining your route.It is a good practise to always name routes. For example: it allows you to just change the url without having to worry about your redirects breaking, since they use the name that hasn’t changed.