mercredi 29 janvier 2020

UpdateOrCreate with model instance

I am using PHP 7.1.33 and Laravel Framework 5.8.36.

I am getting receiving data from a database row-by-row and I am creating a model using updateOrCreate() like the following:

foreach ($arr as $v) {

    $product = new Product();
    $product->name = $v['name'];
    $product->url = $v['url'];
    $product->price = $v['price'];

    // save
    $matchThese = ['name' => $name, 'url' => $url];
    $product->updateOrCreate($matchThese);
}

However, nothing gets created.

Any suggestions what I am doing wrong?

I appreciate your replies!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire