我使用laravel 5.3
我用这个:https://github.com/jenssegers/laravel-mongodb
我的laravel雄辩是这样的:
$data = Employee::select('id', 'name', 'salary', 'description')
->find($id);
我的模型是这样的:
<?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'];
...
}
问题是,执行时,软删除的项目会出现在那里。有什么问题?
答案 0 :(得分:2)
您使用的错误特征use Illuminate\Database\Eloquent\SoftDeletes;
仅适用于Laravel Eloquent模型。
对于Jenssegers \ Mongodb,您需要使用:
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
答案 1 :(得分:0)
您可以在toArray()
类中覆盖Employee
方法。
function toArray() {
return [
'id' => $this->id,
'name' => $this->name,
'salary' => $this->salary,
...etc // dont put deleted_at here
]
}