小编Dua*_*ade的帖子

Laravel背包列出具有场关系的值

我试图列出一个表中的值,其中包含模型中的关系,但显示的是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)

php laravel backpack-for-laravel

1
推荐指数
1
解决办法
2167
查看次数

标签 统计

backpack-for-laravel ×1

laravel ×1

php ×1