1

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>
5
  • Your employers/job/save/{id} route has a / prefixed - maybe try removing that? Commented Nov 3, 2014 at 9:08
  • Oh, also I don't think you can form parameterised routes by specifying the whole thing - you do something like this (using your named route): {{ Form::open(['route' => ['saveJob', base64_encode($jobData->id)], 'class' => 'form-group' /* etc. */]) Commented Nov 3, 2014 at 9:13
  • @alexrussell Have removed the prefix and the result is still the same thanks Commented Nov 3, 2014 at 9:16
  • I did that too but the result was still the same! @alexrussell Commented Nov 3, 2014 at 9:26
  • see my answer for details on how to use Form::open() correctly and a link to the docs to hopefully help you out further. Commented Nov 3, 2014 at 9:31

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot have fixed the error now I have another issue
No problem - if it answered your question, you should mark it as the answer so others finding the question in the future know that it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.