vendredi 26 juin 2020

Laravel 5.2 Eloquent softdelete not working

I have a softdelete trait in my model. I've been trying to delete the file in db but is not working. Here's my model:

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class File extends Model
{
    use SoftDeletes;

    protected $table = 'files';

    protected $dates = ['deleted_at'];
}

My migration file:

public function up()
{
    Schema::table('files', function (Blueprint $table) {
        $table->softDeletes();
    });
}

And in my controller, I'm doing it this way.

$fileID = explode('/', $img)[1];

$JobImage = JobImage::where('file_id', $fileID)->update(['file_id' => null]); <- I'm updating first the column value of it's relationship to null, which works well.
$file = File::where('id', $fileID)->delete();

I don't understand if which part do I lack?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire