Laravel 5.4 - Can't update mysql table column

So I am using this DB facade and eloquent in updating a table column

$affectedRows = DB::table('Users')
            ->where('Phone',$phonenumber)
            ->update(['IsActivated' => 'Y']);

      

or this one:

$affectedRows = Users::where('Phone','=',$phonenumber)
->update(['IsActivated' => 'Y']);

      

but I ran into this error when I access the url

 <span class="exception_message">SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `users` where (`0` = Phone and `1` = = and `2` = 0000000000) limit 1)</span>

      

+3


source to share


2 answers


Can you try using



$affectedRows = Users::where('Phone',$phonenumber)->update(['IsActivated' => 'Y']);

      

+1


source


Try it in that exact order and let us know which commands are giving the error. Of course, I'm using users and phone, not users and phone. It will not affect the request. First add these helper lines to your users model, right aboveclass Users extends Model

/**
 * App\User
 *
 * @property int $id
 * @property string $phone
 * @property-read \App\User $user
 * @method static wherePhone($value)
 * @mixin \Eloquent
 */

$results = DB::table('users')->where('id', '1')->first();
dd($results);
$results = DB::table('users')->where('id', '1')->get();
dd($results);
$results = DB::table('users')->where(['phone' => '000000000000'])->get();
dd($results);
$results = DB::table('users')->where('phone', '000000000000')->get();
dd($results);
$results = DB::table('users')->where('phone', $phonenumber)->get();
dd($results);
$results = DB::table('users')->wherePhone($phonenumber)->get();
dd($results);

      



If none of these functions work, then there is a problem with your model. Since no results were found, update is not possible. You can exchange DB::table('users')->where(...)

forUsers::where(...)

Has your change titled User Model changed Users.php

instead User.php

? I had your problem a while ago, but I can't remember what the reason is. This is due to the settings of the user model.

+1


source







All Articles