Question

I am not sure why this keep happening, I tried several different work around and nothing seems to work :/. I have an edit view in my laravel application and I am trying to update the content and I keep getting the MethodNotAllowedHttpException error.

THE EDIT VIEW

@extends('layouts.master')

@section('content')
<div class="container profile-wrapper" style="position: relative;top:170px;">
        <div class="col-lg-8 profile-content">
            <div class="panel panel-default">
                <div class="panel-heading">{{ucwords($user->firstname)}}, Update Your Profile Below</div>
                @if($errors->any())
                <div class="alert alert-error">
                    <a class="close" data-dismiss="alert" href="#" aria-hidden="true">&times;</a>
                    {{ implode('', $errors->all('<li class="error">:message</li>')) }}
                </div>
                @endif
                <div class="panel-body">

                    {{ Form::open(array('method' => 'PUT','url'=>'user/profile/update', 'class'=>'form-inline edit-form')) }}


                    <fieldset>
                        <legend>Personal Information</legend>
                            <div class="form-group">
                                <label for="firstname">First Name</label>
                                <input type="text" value="{{$user->firstname}}" class="form-control input-sm" id="firstname" placeholder="Enter Your First Name">
                            </div>

                            <div class="form-group">
                                <label for="lastname">Last Name</label>
                                <input type="text" value="{{$user->lastname}}" class="form-control input-sm" id="lastname" placeholder="Enter Your Last Name">
                            </div>

                        <div class="form-group">
                            <label for="zipcode">Zip Code</label>
                            <input type="text" value="{{$user->zipcode}}" class="form-control input-sm" id="zipcode" placeholder="Enter Your 5 digit Zip Code">
                        </div>


                    </fieldset>



                    <fieldset>
                        <legend>Professional Information</legend>


                        <div class="form-group">
                            <label for="experience">Years Experience</label>
                            <input type="text" value="{{$user->temp_experience}}" class="form-control input-sm" id="experience" placeholder="Enter Years of Experience">
                        </div>


                        <div class="form-group">
                            <label for="hourlyrate">Hourly Rate</label>
                            <input type="text" value="{{$user->temp_hourly_rate}}" class="form-control input-sm" id="hourlyrate" placeholder="Enter Your Hourly Rate">
                        </div>

                        <div class="form-group">
                            <label for="zipcode">Willingness to Travel</label>
                            <select name="temp_travel" class="form-control input-sm">
                                <option value="{{$user->temp_travel}}">{{$user->temp_travel}}</option>
                                <option value="1-15">1-15</option>
                                <option value="15-25">15-25</option>
                                <option value="25-35">25-35</option>
                                <option value="35-45">35-45</option>
                                <option value="35-50">35-50</option>
                            </select>
                        </div><!-- end .form-group -->

                        <!-- conditional statement for different temp types -->

                        <div class="form-group mtop-20">
                            <label for="temp_software_experience">Software Experience:</label><br>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Practiceworks"> Practiceworks
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Softdent"> Softdent
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Ortho trac"> Ortho trac
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Dentrix"> Dentrix
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Easy Dental"> Easy Dental
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Practiceworks"> Eaglesoft
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="temp_software_experience" value="Other"> Other
                            </label>

                        </div><!-- end .form-group -->


                    </fieldset>


                    <div class="form-group">
                        {{Form::hidden('id', $user->id)}}
                        {{ Form::submit('Update', array('class'=>'btn btn-primary form-control'))}}
                    </div>

                        {{ Form::close() }}

                    </div><!-- end .panel-body -->

                </div><!-- end .panel/default -->

            </div><!-- end .profile-content -->

            <div class="col-lg-4">
                image
            </div>
        </div><!-- end .container/profile-wrapper -->
@stop

Routes Route::put('user/profile/update/', array('uses' => 'UserController@putUpdate'));

Controller

public function putUpdate()
    {

        $id = Input::get('id');
        // validate
        // read more on validation at http://laravel.com/docs/validation
        $rules = array(
            'firstname' => 'required|min:3|alpha',
            'lastname' => 'required|min:3|alpha',
            'zipcode' => 'required|min:5|numeric'
        );
        $validator = Validator::make(Input::all(), $rules);

        // process the login
        if ($validator->fails()) {
            return Redirect::to('user/profile/' . $id . '/edit')
                ->withErrors($validator)
                ->withInput();
        } else {
            // store
           User::update($id, array(
            'firstname'       => Input::get('firstname'),
            'lastname'      => Input::get('lastname'),
            'zipcode' => Input::get('zipcode')

        ));
            // redirect
            return Redirect::to_route('show', $id)->with('message', 'User Updated!');
        }

    }
Was it helpful?

Solution

You have to pass ID with form.

Change the following line

{{ Form::open(array('method' => 'PUT','url'=>'user/profile/update', 'class'=>'form-inline edit-form')) }}

TO

{{ Form::open(array('method' => 'PUT','url'=> array('user/profile/update', $user->id), 'class'=>'form-inline edit-form')) }}

In your controller:

public function putUpdate($user_id)

If you use put as http method, Laravel will expect an ID with form. Please use Form::model() for editing. if you use Form::model() Laravel will fill up the form automatically and you don't have to do "{{$user->temp_hourly_rate}}"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top