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 Answer
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.
deleted(for example) and select only rows withdeleted = 0, and when deleting set that flag to1