mercredi 5 septembre 2018

How to show and edit same blade in laravel

I have a user and profile table and user_id is the foreign key in the profile table and oneto one relationship. Now I am trying to show the data of user and profile in text field at the profile blade. Also, I want to save edit data in using same text field by clicking save change button. I can showing the user table data using value="" but confused to show profile data and how to edit user and profile data. How can I edit the all data?

Profile Blade

<div class="tab-pane active" id="tab_1_1">
<form role="form"  method="POST">
    

    <div class="form-group">

        <label class="control-label">Full Name</label>
        <input type="text" value="" name="name"  class="form-control">
    </div>

    <div class="form-group">
        <label class="control-label">Email</label>
        <input type="text" value=""  name="email" class="form-control"> </div>
        <div class="form-group">
            <label class="control-label">Mobile Number</label>
            <input type="text" value="" name="mobile" class="form-control">
        </div>


        <div class="form-group">
            <label class="control-label">Organization</label>
            <input type="text" value=""  name="organization" class="form-control">
        </div>
        <div class="form-group">
            <label class="control-label">Department</label>
            <input type="text" value="" name="department" class="form-control">
        </div>
        <div class="form-group">
            <label class="control-label">Designation</label>
            <input type="text" value="" name="designation" class="form-control">
        </div>
        <div class="form-group">
            <label class="control-label">Address</label>
            <textarea  class="form-control" rows="3" name="address" value=""></textarea>
        </div>

        <div class="margiv-top-10">
            @if (Auth::user()->id)
            <!-- <button type="submit" class="btn btn-primary">Edit</button> -->
            <a href="" class="btn default"> Save </a>
            @endif
            <a href="javascript:;" class="btn default"> Cancel </a>
        </div>
    </form>
</div>

Controller

public function profileDataUpdate(Request $request)
{
    $this->validate($request,[

        'user_id'=> '',
        'organization' => '',
        'department' => '',
        'designation' => '',
        'address' => '',

        ]);

        $users = new User();

        $users->name = $request->name;
        $users->email = $request->email;            
        $users->mobile = $request->mobile;

        $users->save();

        $profiles = new Profile();

        dd($profiles->user_id = $request->user_id);

        $profiles->organization = $request->organization;
        $profiles->department = $request->department;
        $profiles->designation = $request->designation;
        $profiles->address = $request->address;

        $profiles->save();

    return redirect(route('profile'))->with('successMsg','profile Successfully Updated');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire