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');
Related
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"
My api.php route is
Route::get('/allposts','PostController#index');
Controller function is and working with web.php Route file
public function index()
{
$posts= Post::all();
return PostResource::collection($posts);
}
my Resource is toArray function is
public function toArray($request)
{
return parent::toArray($request);
}
Postman link using GET are
"queuetest.com/api/allposts"
"http://queuetest.com/api/allposts"
both are not working
and getting Result in both Post man and browser: Sorry the page your looking for could not be found
Do you get something other than the Sorry the page you're looking for could not be found message when you do var_dump('test');die(); in your index method as the first line.
Edit: try to remove then / before /allPosts
Another edit: check in your RouteServiceProvider if the mapApiRoutes prefix is set to 'api'
If you are using the default route configuration that comes out of the box, you should place your route in routes/api.php if you want to access it in the /api namespace. Right now, the route should be accessible from http://queuetest.com/allposts.
This behavior can be configured in App\Providers\RouteServiceProviders.php. If you have a modified route configuration, there are numerous things that could cause this behaviour, and it is impossible to locate the problem without seeing more code.
I have a route setup which is throwing a 404 in my Laravel 5.6 app.
The problematic route is:
Route::get('/project/{project_id}/issue/create', 'IssueController#create');
If I remove the {project_id} parameter the view loads..but I need to be able to pass this id since I will be using it on this view to create new issues that are assigned to a project. All of the other routes work without issue.
My routes file (web.php) looks like this:
Route::get('/projects', 'ProjectController#index');
Route::get('/project/{project_id}', 'ProjectController#show');
Route::get('/project/{project_id}/issue/{issue_id}', 'IssueController#show');
Route::get('/project/{project_id}/issue/create', 'IssueController#create');
And my create function in the IssueController file is this:
public function create()
{
return view('issue.create');
}
You missed project_id as parameter of your create method. Try this:
public function create($project_id)
{
return view('issue.create');
}
and make a route like this:
Route::get('/project/issue/create/{project_id}','IssueController#create');
I have a problemwith my routes. When I call 'editPolicy' I dont know what execute but is not method editPolicy. I think I have got problem beteweeb this two routes:
My web.php ##
Route::get('admin/edit/{user_id}', 'PolicyController#listPolicy')->name('listPolicy');
Route::put('/admin/edit/{policy_id}','PolicyController#editPolicy')->name('editPolicy');
I call listPolicy route in all.blade.php view like this:
{{ $user->name }}
And call editPolicy route in edit.blade.php view like this:
Remove</td>
My PolicyController.php is:
public function listPolicy($user_id)
{
$policies = Policy::where('user_id', $user_id)->get();
return view('admin/edit',compact('policies'));
}
public function editPolicy($policy_id)
{
dd($policy_id);
}
But I dont know what happend when I call editPolicy route but editPolicy method not executing.
Any help please?
Best regards
Clicking an anchor will always trigger a GET request.
route('listPolicy', $user->id) and route('editPolicy', $policy->id) will both return admin/edit/{an_id} so when you click your anchor, listPolicy will be executed. If you want to call editPolicy, you have to send a PUT request via a form, as defined when you declared your route with Route::put.
Quick note, your two routes have the same URL but seem to do very different things, you should differentiate them to avoid disarray. It's ok to have multiple routes with the same url if they have an impact on the same resource and different methods. For example for showing, deleting or updating the same resource.
Have a look at the documentation.
Assume the following routes in a Laravel 5.5 API:
// custom routes for THIS user (the user making the request)
Route::get('/user', 'UserController#show');
Route::get('/user/edit', 'UserController#edit');
// register CRUDdy resource routes for users
Route::resource('users', 'UserController');
Let's use edit as the example:
public function edit(User $user)
{
...
}
As you can see, the edit route contains a type-hinted $user parameter. This works just fine for the users/13/edit route, as expected. However, I'd to configure the route /user/edit to pass along the $request->user() user object to the function. I don't want to check for the user object in the actual edit method as that could interfere with other validation (for instance, I don't want to default to the current user if someone passes a non-existent user ID, I want to return an error in that case).
In short: how can I register a route to first create a parameter, then pass it to the given controller method? My first thought was to use a closure:
Route::get('/user/edit', function(Request $request){
$user = $request->user();
});
But once inside the closure, I'm not certain how to then carry the request forward to the appropriate controller method.
Instead of a closure, you could make a new controller method that calls edit with the current user.
Let's say your route is this:
Route::get('/user/edit', 'UserController#editSelf');
Then in your controller:
public function editSelf(Request $request)
{
$this->edit($request->user());
}