0

I have a view that shows the data pulled out of the database and the client wants to actually delete some of the records on the view with out actually having to delete the record from the database.I am a newbie in Laravel can anyone suggest the approach I may have to follow to acheive this??

1
  • So create a flag deleted (for example) and select only rows with deleted = 0, and when deleting set that flag to 1 Commented Mar 8, 2018 at 19:57

1 Answer 1

4

You want to use soft deletes. This will add a deleted_at column to your table and set the timestamp that the record was marked as deleted, without actually deleting the record. In your schemas, simply add the following to any table you need soft deleted:

$table->softDeletes();

Your model will need to use the SoftDeletes trait, as well:

<?php

namespace App;

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

class MyModel extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];
}

The trashed method will show whether or not the record has been deleted, and the withTrashed method is used to return results that include deleted records.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.