vendredi 29 avril 2016

Why am I getting a MethodNotAllowedHttpException on a resourceful route?

I keep getting a MethodNotAllowedHttpException error on a resourceful route that I have set up. The patch/put requests exist when I run php artisan route:list, my form refers to jobs.update and passes on the id. I use this same process for all of the application's other modules without such an issue. Any ideas where the exception might be coming from?

My routes file:

// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

//Homepage...
Route::get('/', function () { return view('homepage'); });

// Resourceful modules...
Route::resource('conferences', 'ConferencesController');
Route::resource('pages', 'PagesController');
Route::resource('jobs', 'JobsController');
Route::resource('admin/menu', 'MenuItemsController');



// Actions...
Route::put('admin/menu/{id}/promote', [
    'as' => 'admin.menu.promote', 'uses' => 'MenuItemsController@promote'
]);
Route::put('admin/menu/{id}/demote', [
    'as' => 'admin.menu.promote', 'uses' => 'MenuItemsController@demote'
]);
Route::get('{parent}/{slug}', 'PagesController@show');
Route::get('{slug}', 'PagesController@showSlug');

My update method:

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $job = $this->job->find($id);
        $job->update($request->all());
        return redirect('jobs.index');
    }

My form:

        <form action="" method="POST" class="col s12" enctype="multipart/form-data">
        {!! csrf_field() !!}
        <div class="row">
            <div class="input-field col s12 m6">
                <input type="text" name="position" id="position" class="validate" placeholder="Position" value="">
                <label for="position" class="col-sm-3 control-label">Position</label>
            </div>
            <div class="input-field col s12 m6">
                <select name="type" id="type">
                    @if($job->type == "full")
                        <option value="" disabled selected>Type</option>
                        <option value="full" selected>Full-time</option>
                        <option value="part">Part-time</option>
                        <option value="other">Other</option>
                    @elseif($job->type == "part")
                        <option value="" disabled selected>Type</option>
                        <option value="full">Full-time</option>
                        <option value="part" selected>Part-time</option>
                        <option value="other">Other</option>
                    @elseif($job->type == "other")
                        <option value="" disabled>Type</option>
                        <option value="full">Full-time</option>
                        <option value="part">Part-time</option>
                        <option value="other" selected>Other</option>
                    @else
                        <option value="" disabled selected>Type</option>
                        <option value="full">Full-time</option>
                        <option value="part">Part-time</option>
                        <option value="other">Other</option>
                    @endif
                </select>
                <label>Type</label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m6">
                <input type="text" name="reports_to" id="reports_to" class="validate" placeholder="Reports to" value="">
                <label for="reports-to" class="col-sm-3 control-label">Reports to</label>
            </div>
            <div class="input-field col s12 m6">
                <input type="text" name="office_department" id="office_department" class="validate" placeholder="Reports in office" value="">
                <label for="office_department" class="col-sm-3 control-label">Reports in office</label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m6">
                <input type="date" class="datepicker" name="start_date" id="start_date" class="validate" value="">
                <label for="start-date" class="col-sm-3 control-label">Start date</label>
            </div>
            <div class="input-field col s12 m6">
                <input type="date" class="datepicker" name="application_due_date" id="application_due_date" class="validate" value="">
                <label for="application_due_date" class="col-sm-3 control-label">Application Due Date</label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m6">
                <input type="text" name="city" id="city" class="validate" placeholder="City" value="">
                <label for="city" class="col-sm-3 control-label">City</label>
            </div>
            <div class="input-field col s12 m6">
                <input type="text" name="state" id="state" class="validate" placeholder="State" value="">
                <label for="state" class="col-sm-3 control-label">State</label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m6">
                <input type="text" name="institution" id="institution" class="validate" placeholder="Institution" value="">
                <label for="institution" class="col-sm-3 control-label">Institution</label>
            </div>
            <div class="input-field col s12 m6">
                <input type="text" name="salary_range" id="salary_range" class="validate" placeholder="Salary Range" value="">
                <label for="institution" class="col-sm-3 control-label">Salary Range</label>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m12">
                <p class="col-sm-3 control-label">Job Description</p>
                <textarea name="job_description" id="job_description" class="mce validate"></textarea>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m12">
                <p class="col-sm-3 control-label">Job Duties</p>
                <textarea name="job_duties" id="job_duties" class="mce validate" ></textarea>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m12">
                <p class="col-sm-3 control-label">Qualifications</p>
                <textarea name="qualifications" id="qualifications" class="mce validate" ></textarea>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m12">
                <p class="col-sm-3 control-label">Benefits</p>
                <textarea name="benefits" id="benefits" class="mce validate" ></textarea>
            </div>
        </div>
        <div class="row">
            <div class="input-field col s12 m12">
                <p class="col-sm-3 control-label">Application Procedure</p>
                <textarea name="application_procedure" id="application_procedure" class="mce validate" ></textarea>
            </div>
        </div>
        <div class="row">
            <div class="input-field">
                <button class="btn waves-effect waves-light col s12 m3" type="submit" name="action">Submit
                    <i class="material-icons right">send</i>
                </button>
            </div>
        </div>
    </form>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/26ANAAW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire