Update on laravel

1

I am new using laravel and would like to know how to pass the following query to laravel

UPDATE users
INNER JOIN tm_employee ON users.id = tm_employee.UserId 
SET users.groupId = '' 
WHERE tm_employee.id = ''
    
asked by gmrYaeL 23.10.2018 в 22:30
source

2 answers

0

See if it serves you like this:

 DB::table('users')
   ->join('employee', 'users.id', '=', 'employee.UserId')
   ->where('employee.id','')
   ->update([ 'employee' => '' ]);
    
answered by 23.10.2018 / 22:37
source
0
  

If you are working each of your tables by means of the models of   Laravel, you should do the following

On the controller

Here you can invoke the User model in this way

use App\User;

After that, your query should look like this

$data = User::join('employee', 'users.id', '=', 'employee.UserId')
   ->where('employee.id','')
   ->update([ 'employee' => '' ]);

Finally, in order for this to work, you must go to the model User and declare the following

public $timestamps = false;

WHAT HCIE WAS

  • the above is done so that this does not try to update your column updated_at , that is, ignore it
  • The columns and their values that will be used in the update are sent within the update method under the key = > value format
  • answered by 23.10.2018 в 22:59