'firstOrNew where MONTH and YEAR laravel [closed]

$matchThese = array('product_id' => 8789, 'MONTH(date_created)' => '04');
$result = ExpiryPrepayment::firstOrNew($matchThese);
$result->payment_status = 1;
$result->save();

***====>'MONTH(date_created)' => '04'***

Help me get condition only month or year in column date_created



Solution 1:[1]

Why are you sending an array at a firstornew? This is basically a string that you are building an array with in the eloquent. Inserting an array will not work. Really the product_id should be a unique so you only need that value in your where.

So it would be something like this...

firstOrNew(['product_id' =>  $product_id]);

$product_id being the variable of the unique id. Then if you have tons of products to add just loop over the array of product ids and it will either make a new row at your save or update the product when it finds it first.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1