Wednesday, April 12, 2017

How to get all rows (without soft deleted) from a table in Laravel?

I use laravel 5.3

I use this :https://github.com/jenssegers/laravel-mongodb

My laravel eloquent is like this :

$data = Employee::select('id', 'name', 'salary', 'description')
                ->find($id);

My model is like this :

<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; 
use Jenssegers\Mongodb\Eloquent\HybridRelations;
class Employee extends Eloquent
{
    use HybridRelations;  
    use SoftDeletes;
    protected $connection = 'mongodb';
    public $table = 'employees';
    protected $dates = ['deleted_at'];
    ...
}

The problem is, when executed, the soft deleted items appears there. What is wrong?



via samuel toh

Advertisement