我的模型看起来像:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Location extends Model{
use SoftDeletes;
// Name of our database table
protected $table = 'locations';
// Column for soft deletes
protected $dates = ['deleted_at'];
// Columns that are mass assignable
protected $fillable = ['name', 'address', 'city'];
}
当我致电Location::get()
时,默认情况下会返回deleted_at
列。
如何在未明确指定的情况下阻止返回此列?
答案 0 :(得分:1)
您可以使用$hidden
这样的属性:
protected $hidden = ['deleted_at'];
有时您可能希望限制模型数组或JSON表示中包含的属性,例如密码。为此,请向模型添加$ hidden属性: