samedi 21 mai 2016

Laravel 5 replicate() handle columns that have unique attribute

I am using laravel's replicate() method of a Model to generate a copy of exiting instance. It works fine if there are no columns that are to be unique

In my case there are some columns that are to be unique so I use this

    $pr = Products::find(\Input::get('id'))->replicate();
    $pr['product_code'] = $pr->product_code . '_'.$pr['id'];
    $pr['name'] = $pr->name . '_'.$pr['id'];
    $pr->save();

This will make sure that if a product is replicated once it will handle the unique column problem. But if the product is replicated again it will cause the problem again.

How I can I solve this issue



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/25f0ma4
via IFTTT

Aucun commentaire:

Enregistrer un commentaire