Laravel假设数据库表是模型名称的复数形式 [英] Laravel assumes the database table is the plural form of the model name

查看:522
本文介绍了Laravel假设数据库表是模型名称的复数形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Laravel假定数据库表是模型名称的复数形式.但是,如果我的表名是新闻",而我仍想使用此功能怎么办?我应该将其更改为新闻"还是应该使用新"作为型号名称?

By default, Laravel is assuming that the database table is the plural form of the model name. But what if my table name is "news" and i still want to use this feature? should i change it to "newses" or should i use "new" for the model name?

推荐答案

您可以通过在模型上定义表格属性来指定自定义表格,如下所示:

You may specify a custom table by defining a table property on your model as below

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
/**
 * The table associated with the model.
 *
 * @var string
 */
protected $table = 'my_flights';
}

参考: https://laravel.com/docs/5.1/eloquent

这篇关于Laravel假设数据库表是模型名称的复数形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆