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

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

问题描述

默认情况下,Laravel 假设数据库表是模型名称的复数形式.但是如果我的表名是news"并且我仍然想使用这个功能怎么办?我应该将其更改为newses"还是应该使用new"作为模型名称?

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 IlluminateDatabaseEloquentModel;

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天全站免登陆