What is soft delete?
Soft delete often use to hold value or record that user might delete and restore back when needed (involve database and crud ). Soft delete require Illuminate\Database\Eloquent\SoftDeletes and declared on a model. Here is our example that might help you:Model View
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Catalogue extends Model { /** * The attributes that are mass assignable. * * @var array */ use softDeletes; protected $fillable = array('id','type','status'); protected $dates = ['deleted_at']; }
Controller
public function destroy($id)
{
$alumni = Alumni::findOrFail($id);
$alumni->deleted();
}
Soft delete will not remove permanently your record instead 'deleted_at' will tell you the timestamp of your record has been deleted and thus hide the record from showing it to the user .
Reference
http://stackoverflow.com/questions/22426165/laravel-soft-delete-posts
No comments:
Post a Comment