eddy1992's avatar

Form Model Binding

Hi I am making a crud app in which I want I am trying to use the update a profile. I am aware of form model binding in laravel 5 so that we could populate the feilds. Could any one tell me how will it work .

My controller :

/**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        $profile = Profile::find($id);
        return view('paidintern/profile-edit', compact('profile')); 
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        //
    }

My Form :

{!!Form::model(array('url'=>'profile','files'=>true, 'method' => 'patch'))!!}
                    <div class="row main-blog">
                        <div class="col-sm-12">
                            <h2>Profile</h2>
                            
                            <div class="form-group" id="job-title-group">
                                <label for="job-title">Your Phone Number</label>
                                <input type="integer" class="form-control" id="job-title" placeholder="e.g. Add Your Number" name="profile_phone">
                            </div>

                            <div class="form-group" id="job-title-group">
                                <label for="job-title">Where Are You Currently located?</label>
                                <input type="text" class="form-control" id="job-title" placeholder="e.g. Add Your Location" name="profile_location">
                            </div>

                            <div class="form-group" id="job-type-group">
                                <label for="job-type">How much work experience do you have?</label>
                                <select  class="form-control" id="job-type" name="profile_experience">
                                    <option>Choose a Category</option>
                                    <option>0</option>
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                </select>
                            </div>

                            <!--**** Text Editor For Internships ****-->
                            <div class="form-group wysiwyg" id="job-description-group">
                                <label>What are your Key Skills? If Any.</label>
                                <textarea  id="aditor" name="profile_skills" contenteditable="true"></textarea>
                            </div>
                            <!--**** Text Editor Ends ****-->   

                            <div class="form-group" id="job-type-group">
                                <label for="job-type">Please select your Basic Education</label>
                                <select  class="form-control" id="job-type" name="profile_education">
                                    <option>Choose a Category</option>
                                    <option>Not Pursuing Graduation</option>
                                    <option>B.A</option>
                                    <option>B.Arch</option>
                                    <option>BCA</option>
                                    <option>B.B.A</option>
                                    <option>B.Com</option>
                                    <option>B.Ed</option>
                                    <option>BDS</option>
                                    <option>BHM</option>
                                    <option>B.Pharma</option>
                                    <option>B.Sc</option>
                                    <option>B.Tech/B.E.</option>
                                    <option>LLB</option>
                                    <option>MBBS</option>
                                    <option>Diploma</option>
                                    <option>BVSC</option>
                                    <option>Other</option>
                                </select>
                            </div>

                            <!-- <div class="Form-group">
                                {!!form::label('fileupload', 'File Upload:')!!}
                                <input id="input-1" type="file" class="file" name="photo">
                            </div> -->
                        </div>
                    </div>
            </div>
                    <div class="row text-center">
                        <p>&nbsp;</p>
                         <button type="submit" class="btn btn-primary btn-lg">Submit</button>
                    </div>
                <!-- </form> -->
            {!!Form::close()!!}

Thanks .

0 likes
1 reply
mercuryseries's avatar

@eddy1992

Change

{!! Form::model(array('url'=>'profile','files'=>true, 'method' => 'patch')) !!}

to

{!! Form::model(Auth::user(), array('url'=>'profile', 'files'=>true, 'method' => 'PATCH')) !!}

And in your controller you can simply do

 public function edit($id)
 {        
    return view('paidintern/profile-edit'); 
 }

If you doesn't use the $profile variable at all.

So as you can see the $id parameter is now useless. You can maybe add a specific route if you want that doesn't require this $id parameter.

Please or to participate in this conversation.