魔众短链接系统使用Grid、Form、Detail如何使用自定义主键ID?

魔众短链接系统 / 文档中心
文档中心
开发教程
安装常见问题

系统默认使用 id 作为主键,如果需要使用自定义主键,可以通过数据模型类的方法来实现。

第一步,定义数据模型类

namespace Module\News\Model;

use Illuminate\Database\Eloquent\Model;

class News extends Model
{
    protected $table = 'news';
    // 这里可以自定义主键
    protected $primaryKey = 'nid';
}

第二步,使用数据模型类作为Form、Detail、Grid的操作对象

// 表单
$form = Form::make(News::class);
// 详情
$detail = Detail::make(News::class);
// 数据表格
$grid = Grid::make(News::class);
// 快速CRUD
$builder->init(News::class)
QQ
微信
公众号