douzengjian1535 2016-11-24 10:12 采纳率: 100%
浏览 80
已采纳

Laravel有很多很多关系,有没有办法自动生成数据透视表?

I there possibly a way to have Laravel genrating automatically the table containing pivot indexes on a ManytoMany Relationship. Or maybe via artisan?

Until now I'm creating my Entity models (e.g. User and Role: a user has many roles and a roles is assumed by many user) I define the belongsToMany method in each model.

Then I create migrations for create_users_table, create_roles_table, and create_role_user_table)

It would be great if there's a command that after creating the two Entities creates the third with n:n relationships table.

(Maybe the answer is goin to be : no it does not exists...)

  • 写回答

1条回答 默认 最新

  • douxie0824 2016-11-24 10:17
    关注

    Yes, using Laravel 5 Generators Extended package:

    php artisan make:migration:pivot User Role

    Install the package and then you will can use this and more new commands. Run php artisan after installing the package to see all the commands you can use.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式