0

Unable to update the data,

Controller Code

public function update(Request $request, $id)
    {
        //

         echo $request->all();
       /* $user= User::find($id);
        $user->update($request->all());
         $user->save();
         return redirect('user');*/
    }

data not getting updated that's why used echo.

When used

echo $request->all();     (line 86)

got the error

 (1/1) ErrorException
    Array to string conversion
    in userController.php (line 86)

used

 dd($request->all());

got result

array:14 [▼
  "_method" => "PUT"
  "_token" => "zDkzEpJCKscUgAGvgFQwu6gKbtRwm8N8MdBHC9em"
  "userType" => "Admin"
  "firstName" => "Sda"
  "lastName" => "ad"
  "gender" => "M"
  "personalContact" => "123"
  "officeContact" => "132"
  "email" => "ads"
  "country" => "ds"
  "state" => "ds"
  "city" => "ddsf"
  "address" => "dsf"
  "zipCode" => "1234"
]

my model

class User extends Model
{
    //
    protected $fillable = [
        'userType', 'firstName', 'lastName', 'gender','personalContact','officeContact','email','country','state','city','address','zipCode'
    ];
/*  public $incrementing = false;*/
}

User table Migration

 Schema::create('users', function (Blueprint $table) {
            $table->increments('Id');
            $table->uuid('userType'); 
            $table->string('firstName');
            $table->string('lastName');
            $table->char('gender');
            $table->string('personalContact');
            $table->string('officeContact');
            $table->string('email');
            $table->uuid('country');
            $table->uuid('state');
            $table->uuid('city');
            $table->string('address');
            $table->integer('zipCode');
            $table->rememberToken();
            $table->timestamps();
        });

can anyone please let me know, What I have done wrong

1 Answer 1

1

You need to use $request->only(['userType, 'firstNAme', 'lastName']) etc etc etc when filling your model. You cannot pass in the indexes like _method and _token, otherwise it will attempt to save those to the database and not know what to do with them.

Sign up to request clarification or add additional context in comments.

2 Comments

Does your User model have the $fillable or $guarded properties set? If so they need to line up with what you're passing in to the update() method. Post your Use model class if you will.
I have kept protected $fillable = [ 'userType', 'firstName', 'lastName', 'gender','personalContact','officeContact','email','country','state','city','address','zipCode' ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.