WellNo
WellNo

Reputation: 659

Laravel 5, change value in database

I have an Enum field in my database with two options. Active and Inactive.

I allready have all the products I want to edit.

$products= Products::whereIn('id', $arr['id'])->get();
                foreach($products as $product)
                {
                      //
                }

The enum column field in my database is called 'status' and also is written in my Model fillable section. Currently all the products in my $products variable have the 'active' status. Now I want to change the status from active to inactive.

I also have no clue how I can do that. I never worked with Enum fields and just found methods like DB::statement('sql code here'). Isn't there a other way for just simply change the value of the status field?

Upvotes: 0

Views: 991

Answers (1)

thefallen
thefallen

Reputation: 9749

Have you tried this:

$products= Products::whereIn('id', $arr['id'])->get();
foreach($products as $product)
{
    $product->fill(['status' => 'inactive'])->save(); 
}

Upvotes: 3

Related Questions