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');
Related
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');
I'm new to laravel. I'm using laravel 5.8 . I define a new route name calledsignin in routes/web.php and call it in my controller to redirect to this page. but laravel throw an exception with the error "Method Illuminate\Routing\Redirector::signin does not exist
//.../routes/web.php
Route::get('/registration', 'Mycontrollers#index')->name('signin');
//in Mycontroller.php
//some code
public function index(){
//some code
return redirect()->signin();
}
but if I used return redirect()->route('signin'); it works fine
The error you are getting is correct, the Redirector class does not contain a function signin().
If you want to redirect to another route, you have to either use the route name (as in your working example), or the full class with its namespace. For example:
return redirect()->action('Mycontrollers#index');
You could also redirect directly to the path using to():
return redirect()->to('/registration');
I am having issues getting the page to render when using a parameter in a create controller. My show controller works but my create controller doesn't. The error thrown is a 404.
Sorry, the page you are looking for could not be found.
The URL is:
http://myapp.test/country/us/state/create
My controller looks like:
// Show
public function show(Country $country, State $state){
return view('state.show', compact('state'));
}
// Create
public function create(Country $country) {
return view('state.create', compact('country'));
}
My route looks like:
Route::get('country/{country}/state/{state}', 'StateController#show');
Route::get('country/{country}/state/create', 'StateController#create');
You need to flip your routes around to be
Route::get('country/{country}/state/create', 'StateController#create');
Route::get('country/{country}/state/{state}', 'StateController#show');
Laravel processes routes in the order that they are defined, so in your current code Laravel was seeing create as a state.
I'm fairly new to Laravel. I'm having a problem with routing.
Route::group(['prefix'=>'api/v1'],function(){
Route::resource('results','RequestController');
Route::get('results/getByName/{name}','RequestController#getByName');
Route::get('results/getLastTen','RequestController#getLastTen');
});
The problem is that the last route under prefix api/v1 does not work. When I call it it shows nothing, not even any error.
The code at the requestController is:
public function getLastTen(){
$results=DB::table('latest_random_trends')->limit(10)->get();
return $results;
}
Everything is alright with the code on the controller since it works when I call it from the routes.php file outside of the prefix 'api/v1' like this:
Route::get('results/getLastTen','RequestController#getLastTen');
but when it is inside the prefix it does not work unless I add a variable to it like this:
Route::get('results/getLastTen/{var}','RequestController#getLastTen');
Since you have a Route::resource above it, I think what's happening is that the show method on Resource Controller is getting the route instead of the one you wrote.
Try one the following:
Exclude the show method if you're not going to use it
Route::resource('results','RequestController', ['except' => 'show']);
Move your custom route above the resource route
Route::group(['prefix'=>'api/v1'],function(){
Route::get('results/getLastTen','RequestController#getLastTen');
Route::resource('results','RequestController');
Route::get('results/getByName/{name}', 'RequestController#getByName');
});
For more information, check out the show action on Laravel Docs
I have route:
Route::resource('admin/question', 'QuestionsController');
and function index:
public function index() {
return "Hello";
}
But when I try used index Laravel returned me the error:
Method [show] does not exist.
I'm using the link:
http://localhost:8012/siwz/siwz/public/admin/question
The server is WampServer program.
I can only use index function when I change route file:
Route::get('admin/question/index', 'QuestionsController#index');
Route::resource('admin/question', 'QuestionsController');
In Laravel version 5.3 I did not have to do it, it was enough to use:
Route::resource('.../...', '...Controller');
Actually, the URL is going to the correct function. admin/question should go to index. admin/question/{question} is the route that goes to show.
Take a look here and check how Laravel create Resource routes:
https://laravel.com/docs/5.4/controllers#resource-controllers
Since that you didn't provide your full routes. I am guessing that the link you were accessing is going to the wrong controller. You should check the ordering of the routes. Maybe you are accessing something like this on your route,
Route::resource('admin','AdminController');
And the AdminController doesn't have a method show(). Thats why laravel return that error.
Here's you can do
Comment out the rest of routes except route that you are accessing.
Try to reorder the affected routes. Maybe Laravel is confused with your route.