Monday, April 10, 2017

Laravel destroy reporting deleted status incorrectly

I have this code to pull a bunch of transaction ids and then destroy them.

$importedTransactionIds = ImportedTransaction::where('bank_account_id', $bankAccount->id)->pluck('id')->toArray();

if (!empty($importedTransactionIds)) {
    ImportedTransaction::destroy($importedTransactionIds);
}

There are 2000 transactions and destroy returns the exact same count. However, when I go to the database the deleted_at timestamp is still null.

When I output the model from the Laravel destroy function it shows that the deleted_at timestamp is set on the model.

foreach ($instance->whereIn($key, $ids)->get() as $model) {
    if ($model->delete()) {
        $count++;
    }
    dd($model);
}

Here is the simplified output

attributes: array:14 [
    ...
    "deleted_at" => "2017-04-10 12:58:35"
    ...
]
original: array:14 [
    ...
    "deleted_at" => null
    ...
]

Here is my model:

class ImportedTransaction extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];
}



via Michael St Clair

Advertisement