I would like to start using soft delete models with the query builder of Laravel
By the way, I created the column deleted_at and I implemented soft delete models in the model.
Request.php:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request as Req;
use Illuminate\Database\Eloquent\SoftDeletes;
class Request extends Model
{
use SoftDeletes;
}
RequestController function:
public function already_deleted_checker($id_req)
{
$request_customer_match_rip = DB::table('requests')->onlyTrashed()->select('id')->where('id', '=', $id_req)->get();
$request_customer_match_rip_len = count($request_customer_match_rip);
if ($request_customer_match_rip_len > 0) {
return true;
}
}
The function already_deleted_checker should check if the value in the deleted_at column is null or not... but unfortunately when I run the function I visualize the following error in the browser:
Call to undefined method Illuminate\Database\Query\Builder::onlyTrashed()
Can help?
Model, Request, Controllerbecause those already exist and sometimes it can bring only trouble!