How to display and update in same blade

Posted 1 year ago by _Zaman

Hi, I have 2 table user and profiles. user_id is foreign key of profile table. In the profile view I want to show all the data of user and profile in the text box and any user can update their data to pressing save change button. But here is showing an error.

        $users = User::all();
        $profiles = Profile::all();
        return view('admin\profile',compact('users','profiles'));
        //return view('admin\profile',compact('profiles'));

public function profileDataUpdate(Request $request,$id)

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


            $users = User::find($id);

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


                $profiles = Profile::find($id);

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


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

   public function users() {
        return $this->belongsTo('App\User','profile');

public function profiles() {
        return $this->hasOne('App\Profile','user_id');

Route::post('profileDataUpdate/{id}','[email protected]')->name('profileDataUpdate');

<form role="form" action="route('profileDataUpdate',$users->id,profiles->id) }}" method="POST">
    {{ csrf_field() }}
    <div class="form-group">
        <label class="control-label">Full Name</label>
        <input type="text"  value="$profiles->user->name" name="name"  class="form-control"> </div>
        <div class="form-group">
            <label class="control-label">Email</label>
            <input type="text"  name="email" class="form-control"> </div>
            <div class="form-group">
                <label class="control-label">Mobile Number</label>
                <input type="text" name="mobile" class="form-control"> </div>
                <div class="form-group">
                    <label class="control-label">Organization</label>
                    <input type="text" value="{{ $profiles->organization}}" name="organization" class="form-control"> </div>
                    <div class="form-group">
                        <label class="control-label">Department</label>
                        <input type="text" name="department" class="form-control"> </div>
                        <div class="form-group">
                            <label class="control-label">Designation</label>
                            <input type="text" name="designation" class="form-control"> </div>
                            <div class="form-group">
                                <label class="control-label">Address</label>
                                <textarea class="form-control" rows="3" name="address"></textarea>
                            <div class="margiv-top-10">
                                <a href="javascript:;" class="btn green"> Save Changes </a>
                                <a href="javascript:;" class="btn default"> Cancel </a>

Please sign in or create an account to participate in this conversation.