Please make sure that your model imports and uses SoftDeletes
trait to implement soft delete in your model and make sure that your table has deleted_at
field, your model may look like below codes.
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Category extends Model
{
use SoftDeletes;
And in your SoftDelete
function within the controller, I think you miss delete()
function, your function should look like:
public function SoftDelete($id) {
$delete = Category::find($id)->delete();
return redirect()->back()->with('success',' Category Delete Successfully');
}
Once you implement SoftDeletes
trait into your model, delete()
function should mark deleted by filling the deleted_at
with timestamp or DateTime automatically. Once you implement the above codes, onlyTrashed()
should work.
$categories = Category::latest()->paginate(5);
$trashCat = Category::onlyTrashed()->latest()->paginate(3);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…