Laravel - The page you are looking for could not be found - php

I got page 404 when I click the link
I don't know which part is wrong, can someone help me?
sidenav
Request List
route
Route::prefix('dashboard')->middleware('role:superadministrator|administrator|editor|author|contributor')->group( function () {
Route::get('/', 'PagesController#dashboard')->name('dashboard');
Route::resource('/posts', 'PostController');
Route::get('/posts/request-list', 'PostController#indexRequest')->name('posts.indexRequest');
});
Post Controller
public function indexRequest()
{
$posts = Post::where('status', 'On Request')->orderBy('created_at')->paginate(12);
return view('manages.posts.request', compact('posts'));
}
and I have the view

You cannot set a get route after a resource route if they use the same prefix.
The resource route will define posts/{post} as the PostController#show route, equivalent to:
Route::get('posts/{post}', 'PostController#show')
This will conflict with your bottom route and posts/request-list and will evaluate request-list as a post ID ({post}) in the above route.
Set all specific routes before resource routes.

did you try to direct access to your "app-link/posts/request-list"

Related

404 a page not found in laravel

I'm getting a 404 page not found when trying to use the 'users/{id}' route, the route
leads to the ProfilesController#edit method
Profiles Controller:
public function edit($id){
$user = User::findOrFail($id);
return view('profiles.edit', compact('user'));
}
here is the routes in my web.php;
Route::get('/users/{id}', 'ProfilesController#edit')->name('user.edit');
Route::put('/users/{id}/update', 'ProfilesController#update')->name('user.update');
and i have a edit.blade file in my profiles folder
Change route to this, the call users/{id} instead of profile/{id}. Otherwise you can stick with your approach by using the second option below.
Route::get('/users/{id}/edit', 'ProfilesController#edit')->name('user.edit');
Route::put('/users/{id}', 'ProfilesController#update')->name('user.update');
Also you are trying to access the route profile/{id} but which for my undestanding it is not defined. You either will have to change your route to:
Route::get('/profile/{id}', 'ProfilesController#edit')->name('user.edit');
Route::put('/profile/{id}/update', 'ProfilesController#update')->name('user.update');

Laravel routing strange behavior

I have a single domain/subdomain project. In order to see the event by slug, I made this route:
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
});
After my page didn't load correctly, I did a dump in the controller:
public function getView($slug)
{
return $slug;
}
To get to the route I am using this URL: https://example.com/events/slug-example.
The problem is that the route is being hit as I see the response when I change it, but I am not getting the slug, instead I am getting Region object back.
If I do this:
public function getView($region, $slug)
{
return $slug;
}
Then I get the slug back. But I have no idea how is this possible, and how could I do it (I came as another dev on the existing project).
I tried commenting out all the middleware and it is still the same. How can I even make something fill the method if I didn't explicitly say it?
EDIT
I noticed there is binding going on in routes file:
Route::bind('region', function ($value) {
...
});
Now if I dd($value) I get the variable back. How is this value filled? From where could it be forwarded?
Looking quickly it should work, but maybe you was verifying other url.
Make sure you put:
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
routes at the end of routes you showed.
EDIT
If you think that's not the case and you don't have your routes cached you should run:
php artisan route:list
to verify your routes.
EDIT2
After explaining by OPs in comment, domain used for accessing site is:
{region}.example.com
So having $region in controller as 1st parameter is correct behaviour because of route model binding and other route parameters will be 2nd, 3rd and so on.
Instead of
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
});
try
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
});

Laravel basic view returning route does not work

I have this problem when I try to access the page vie link it works properly. But when I try to write the route inside a link in order to access it using navbar, it throws the following Error :
Route [home] not defined. (View: C:\wamp64\www\projectName\resources\views\layouts\master.blade.php) (View: C:\wamp64\www\projectName\resources\views\layouts\master.blade.php)
And my route is as following:
Route::get('/home', function () {
return view('home');
});
This is how I write the route inside the navbar link:
{{ Route('home') }}
Any help is highly appreciated.
When you use named route you have to give name to that particular route. change your code to:
Route::get('/home', function () {
return view('home');
})->name('home);

How to properly define the home (/) route in Laravel?

Let's say I am defining the following route in Laravel 5.3:
Route::resource('bands', 'BandController');
The default route example coming when you start a new Laravel project has the following:
Route::get('/', function () {
return view('welcome');
});
How do I make bands route to be the default one when no controller is called instead of welcome? Meaning /?
I did read docs here but didn't found anything. Any?
Place that block inside laravel/app/routes.php instead of a Controller (4.x)
Place that block inside laravel/app/Http/routes.php instead of a Controller (5.1)
Place that block inside laravel/app/routes/web.php instead of a Controller (5.3)
Route::get('/', function()
{
return view('welcome');
});
You can redirect default to anywhere you want, i.e.:
Route::get('/', function()
{
return Redirect::to( '/bands');
// OR: return Redirect::intended('/bands'); // if using authentication
});
As #Patrick mentioned, you can simply redirect to the /bands route. However, I have to warn you that the redirect will actually change the URL in the navigation pane of the web browser. I would have suggested that you just ask the home route to use the index method of your BandController as follows:
Route::get('/', ['uses'=>'BandController#index']);

Controller Method not found in nesting laravel 4

I'm new in laravel and I got an error and don't really know how to fix it.
I got an error "Controller method not found" when i'm asking for this route : /projet/6/note
My routes.php
Route::controller('projet.note', 'NoteController');
Route::resource('/eleves', 'StudentController');
Route::controller('/auth', 'AuthController');
Route::resource('/user', 'UserController');
Route::resource('/projet', 'ProjectController');
Route::post('/eleves/search', 'StudentController#postSearch');
Route::resource('/classe', 'ClasseController');
Route::controller('/', 'HomeController');
I tried to type php artisan routes to see if the routes was working, and she's not.
I tried then to change controller into resource in the line about NoteController, the routes was there but when i go on the link, same error.
Then i guess i can't do 'projet/note' without that my NoteController is a resource?
It's a problem because i need to nest NoteController to ProjetController.
My only action in NoteController
public function getIndex($id)
{
return View::make('note.noter')
->with('project', Project::find($id))
;
}
Thanks
I hope I understood your question right. This is the best solution I could come up with:
Route::any('projet/{id}/note/{action?}', function($id, $action = 'index'){
$controller = App::make('NoteController');
$action = strtolower($_SERVER['REQUEST_METHOD']).studly_case($action);
if(method_exists($controller, $action)){
return $controller->callAction($action, [$id]);
}
});
This basically does some similar things as Route::controller. First we create a controller instance, then build the action name out of the request method and the second parameter in the route and in the end, call the action (if it exists).

Categories