我有一个名为 agency_persons 的表格,其中已包含一些数据。我使用 php artisan 创建了一个模型:
php artisan make:model AgencyPerson
现在,当我尝试使用Laravel的Eloquent方法时,我面临以下错误:
未找到基准表或视图:1146表
' my_database.agency_people'没有按'吨
Laravel正在寻找人员而不是人。
我知道Laravel正在尝试做正确的事情,我应该首先将我的表命名为 agency_people ,但我无法更改表的名称,因为其他应用程序也在使用此表。
我怎样才能禁止人们对laravel的复数?
答案 0 :(得分:8)
在模型中,添加行
<script language="JavaScript">
<!--
var ss='<span style="font-size: small;"><b>NOTICE:</b> If you are having
trouble finding a pattern, try searching the first three letters of the
pattern name in the search bar. Also, be aware that some sheers may be
photographed with a window pane to show sheer quality.<br>If you are using
Google Chrome and have an issue viewing the library, please switch to another
browser.</span><br><br>';
var upper_limit = 500000000;
//-->
document.body.innerHTML += ss;
function getIP(json) {
document.body.innerHTML += '<iframe frameborder="0" marginheight="0" width="100%"
height="700" src=" ' + 'http://client.richloomfabrics.com/cgi-bin/Wdrv01?
&PARPAR=CON&MELMEL=ALL&PTYPTY=UPH&IPAIPA=' + json.ip +
'&IPACOK=' + RandomNumber(upper_limit) + '&PGMPGM=WC033&>
</iframe>';
}
</script>
<script type="application/javascript" src="https://api.ipify.org?
format=jsonp&callback=getIP"></script>
有关详细信息,请参阅https://laravel.com/docs/5.5/eloquent,查看“表名”部分
答案 1 :(得分:0)
If you are using persons table and person model in laravel. Laravel Pluralization For Person To People will give you this error whatever your query would be:- Base table or view not found: 1146 Table 'lrv_db.people' doesn't exist (SQL: select `posts`.*, `people`.`country_id` from `posts` inner join `people` on `people`.`id` = `posts`.`person_id` where `people`.`country_id` = 1)'
解决方案是:- 在人员模型中定义表,如下所示:
class person extends Model
{ / ** *与模型关联的表。 * * @var字符串 * /
protected $table = 'persons';
}
答案 2 :(得分:-1)
您还可以定义要批量分配的模型属性。您可以使用模型上的$ fillable属性执行此操作。 例如:
protected $fillable = ['title', 'description'];
将属性赋予质量可分配后,可以使用create方法在数据库中插入新记录 使用$ fillable来保护您希望实际允许更新的字段。