Reputation: 15451
Having a problem with redirection.
Example, in this view,
we have the show view for notes of a company named Tiago.
The link that says 'Create Note for Tiago', looks like the following:
<p><a href="{{route('company.companies.notes.create', $company->companyID)}}">Create Note for {{$company->Company_Name}}</a></p>
where $company->companyID is being grabbend from the controller, which looks like this:
public function create(Request $request, $id)
{
//
$company = $request->user()->company()->first();
$notes = NotesCompany::where('companyID', "=", $id)->get();
return view("company.companies.notes.create", compact('company', 'notes'));
}
and has the following route:
GET|HEAD | company/companies/notes/create | company.companies.notes.create | App\Http\Controllers\CompanyNotesController@create | web,company |
Route::resource('company/companies/notes', 'CompanyNotesController',['names'=>[
'index'=>'company.companies.notes.index',
'create'=>'company.companies.notes.create',
'store'=>'company.companies.notes.store',
'edit'=>'company.companies.notes.edit',
'show'=>'company.companies.notes.show'
]]);
The problem is, when pressin in 'Create Notes for Tiago', the following error comes through:
Any debug here? Appreciated
Tiago
Upvotes: 2
Views: 278
Reputation: 62248
Normally the create
resource method does not take any url parameters. It can does, however, when attempting to use nested resources. It looks like you are attempting to use nested resource routes, but have not set it up properly.
Your route needs to look like:
Route::resource('companies.notes', 'CompanyNotesController',['names'=>[
'index'=>'company.companies.notes.index',
'create'=>'company.companies.notes.create',
'store'=>'company.companies.notes.store',
'edit'=>'company.companies.notes.edit',
'show'=>'company.companies.notes.show'
]]);
This will create urls that look like companies/{company_id}/notes/create
, etc., and that company_id
will be passed into your create
method.
I do not believe there is a way to modify the generated routes when using nested resources. You could attempt Route::resource('company/companies.notes', ...
, but I don't know if that will work.
Upvotes: 1