我试图列出一个表中的值,其中包含模型中的关系,但显示的是id而不是与该id相关的名称:
District.php和迁移:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
class District extends Model
{
use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'districts';
protected $primaryKey = 'id';
// public $timestamps = false;
// protected $guarded = ['id'];
protected $fillable = ['name'];
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
public function county()
{
return $this->hasMany('App\Models\County');
}
Run Code Online (Sandbox Code Playgroud)
迁移: `
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; …Run Code Online (Sandbox Code Playgroud)