mardi 7 mai 2019

Eloquent updateOrCreate hide some columns to while updating like created_at is not updating in update operations

I am using updateOrCreate function to update the record if there record is already available in table based on some condition but I do not want to update one of my column which contains some unique value.

I want to perform the same action to this column like created_at is working while creating the records value is adding to created_at column but while updating it contains the same

to prevent this issue I removed that column name form my $fillable in my model but in this case it is not adding any value to this column

protected $fillable = array
        (
            'uid',
            'channel', 
            'updated_at'
        );

$data = [
                        'uid'                 => Helper::generateUid(),
                        'channel'             => $info['channel'],
                        'created_at'          => time(),
                        'updated_at'          => time(),
                    ]; 

                    $cond = [
                        'channel' => $info['channel'],
                    ];  

                    $isAdded = Templates::updateOrCreate($cond, $data);

Expected result : I don't want to update uid column if details already there.

Actual result : if details are not there it is add value to uid column and other columns also and if details are available then also it is updating uid column.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire