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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置