Reputation: 33
Working on a job portal, so I arrived at a point where employers need to edit their posted jobs,On page load it gave me an error Route [employers/job/save/Mw==] not defined
, please I need help my deadline is 3hours from now!
Here is my code:
Routes:
//Route for Employer's specified Job Editting -> To get ID as argv
Route::get('employers/job/edit/{id}', 'employerController@editJob');
//Route for Employer's to save specified Job after Editting -> To get ID as argv
Route::post('/employers/job/save/{id}', [
'as' => 'saveJob',
'uses' => 'employerController@saveJob'
]);
View:
{{ Form::open(['action'=>'employers/job/save/'.base64_encode($jobData->id),'class'=>'full-job-form', 'id'=>'jobForm','role'=>'form']) }}
<div class="form-group col-lg-12 col-sm-12 col-md-12">
<label class="sr-only" for="">Job Title</label>
<input type="text" class="form-control"
name="job_title" placeholder="Job Title"
value="{{ $jobData->job_title }}">
<span class="help-block">Eg. Marketing Manager</span>
</div>
Upvotes: 1
Views: 542
Reputation: 14202
Your issue is that you're using the action
parameter for your Form::open()
call. This expects the name for a controller method (e.g. {{ Form::open(['action' => 'employerController@saveJob']) }}
. If you want to link to a pre-generated URL use the url
parameter:
{{ Form::open(['url' => 'employers/job/save/'.base64_encode($jobData->id)]) }}
That said, that's not the best practice, as, if you change your routing system, you now have to change all these hardcoded URLs. As such, you should rely on named routing or controller actions.
Now, your route is already named ('as' => 'saveJob'
) so you should actually use the route
parameter of Form::open()
:
{{ Form::open(['route' => ['saveJob', base64_encode($jobData->id)]]) }}
Alternatively, you could use the action
parameter as you are currently trying to do (albeit erroneously):
{{ Form::open(['action' => ['employerController@saveJob', base64_encode($jobData->id)]]) }}
See the docs on forms for more information.
Also, as @TheShiftExchange says, its a bit odd to be using the base 64 encoded id, why not just use the raw id?
Upvotes: 1