Sooraj J
Sooraj J

Reputation: 9

How to insert where condition in mysql query laravel?

I try to insert with code

$info = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->get();

error of insert

$response = $info->insert(array('active' => 1));

Upvotes: 0

Views: 5391

Answers (2)

Shakhawat Hossain
Shakhawat Hossain

Reputation: 91

You should run the update query:

$response = DB::table('role_user')
->where('user_id', $current)
->where('role_id', $id)
->update(array('active' => 1));

Upvotes: 1

KuKeC
KuKeC

Reputation: 4620

You can't insert the same role_user twice, but you can update it

$response = DB::table('role_user')->where('user_id', '=',$current)
->where('role_id', '=',$id)->update(array('active' => 1));

Upvotes: 2

Related Questions