dtoqemais553654797
2017-11-13 16:35
浏览 27
已采纳

如何在laravel中创建一个奇异的模型和表格

I am an absolute beginner in laravel now I undertsand the concept that laravel creates singular model and plural table name e.g

php artisan make:model Admin -m

php artisan migrate

now this will create a model named Admin and a database named admins now logically I don't have a issue with that but it doesn't look clean if there is only one admin why need to have the table name as admins? Shouldn't it be admin? Is there any workaround for that or do I have to just stick with admins?

图片转代码服务由CSDN问答提供 功能建议

我是laravel的绝对初学者,现在我不知道laravel创建奇异模型和复数表名称的概念,例如

  php artisan make:model Admin -m 
 
php artisan migrate 
   
 
 

现在这将创建一个名为的模型 现在逻辑上管理员和名为管理员的数据库我没有这个问题,但如果只有一个管理员为什么需要拥有该表,它看起来并不干净 以管理员身份命名? 不应该是管理员吗? 是否有任何解决方法或我必须坚持管理员

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzhi3779 2017-11-13 16:50
    已采纳

    If you don't want to use the default name for the table, you can overwrite it in your model:

    class Admin extends Model {
        protected $table = 'admin';
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongye9820 2017-11-13 17:02

    This is default behavior. imagine the table as a bag, we have a bag of multiple users, articles or something else. but if you don't feel comfort with laravel standard, you can define your custom table name in your model.

    class Admin extends Model {
    protected $table = 'admin';
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题