i have created route group using middleware.It works perfectly.
But i have one issue where if i navigate url to
http://localhost/laravel-news/public/admin/add-post-new
this without login then it redirect to guest home page
but if i navigate url to
http://localhost/laravel-news/public/add-post-new
without admin in url then it return blank page.now my question is how to show page not found 404 page for that.i am using laravel 5.1
thank you
update
Route::group(['middleware' => 'admin'], function () {
Route::get('add-post-new', function () {
// dd('something');
return view('a.addPost');
});
Route::post('/add-post-new','PostsController@addPost');
Route::get('/all-post', function () {return view('a.all_post'); });
});
By adding the . htaccess file at the same folder location of the index. php it solves the 404 page not found error in my laravel Project.
You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.
A 404 Not Found error occurs when a user is trying to access an asset that either does not exist or has been moved. This commonly occurs when a permalink has been modified and no 301 redirect was put in place to redirect the user to the correct URL.
In your Laravel project folder, create a folder called “errors” in your /resources/views/ folder. Create a file called 404. blade. php in this /resources/views/errors/ folder.
Make a 404.blade.php page in /resources/views/errors/
folder and that page will be shown if:
->findOrFail($modelId);
abort(404);
instead of laravel error for non existing route:
Sorry, the page you are looking for could not be found.
1/1 NotFoundHttpException in RouteCollection.php line 161:
/resources/views/errors/
folderand then just call it with
abort(404);
For example make a route like this:
Route::get('/404', function () {
return abort(404);
});
Try this:
abort(404);
more info http://laravel.com/docs/5.1/routing#throwing-404-errors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With