graffislife's avatar

Update row of database on laravel

I was hoping to change all column payment to 1 f the user order and inventory ID is the same. This is my code. Thanks in advance

  
if($order->user_order_id == $order->inventory->user_id){
DB::table('orders')->update(array('payment' => 1));
} 
0 likes
4 replies
munazzil's avatar

Then you can set in your orderdatabase migration payment as like below

    $table->integer('payment')->default(1);

and in your user Model use as like below then you can use user_order_id as foreign key

protected $primaryKey = 'user_id';
manelgavalda's avatar

Are you sure that you are entering the if statement?

if($order->user_order_id == $order->inventory->user_id){
dd('hey');
DB::table('orders')->update(array('payment' => 1));
} 

If you are entering the if status but is not updating maybe you have the mysql server safe update mode, if you don't want to disable it, you can try something like this:

DB::table('orders')->where('id', 'id')->update(['payment' => 1]);
graffislife's avatar

@munazzil I already set that up. I was planning to change all column payment to 1 if the user order and inventory is the same.

andreich1980's avatar

There must be a query with a join between orders and inventories (or whatever the table name is), then you would add a where like this ->where('orders.user_order_id', '=', DB::raw('inventories.user_id')) and then call ->delete()

Please or to participate in this conversation.