【发布时间】:2019-03-03 15:09:48
【问题描述】:
我浏览了这篇文章... Laravel - name a model using a reserved word
但这并没有提供定义关系的解决方案。
我有一个型号名称Class.php
我必须将它与学生和班级分配联系起来
这是我在 Student.php 中定义的关系:
/**
* Check the Class allocated to Student
*
*@return void
*/
public function class()
{
return $this->belongsToMany('App\Class', 'class_allocations');
}
我已经尝试了所有方法,现在我不想更改我的模型名称。我该如何进行这项工作?我在修补程序上不断收到此错误:
PHP 错误:语法错误,意外的 'Class' (T_CLASS),期待 /home/vagrant/Homestead/app/app/Class.php 中的标识符(T_STRING) 第 7 行
【问题讨论】:
-
相关帖子中没有解释什么? PHP 中不能命名函数和类的保留字,与 Laravel 无关。您在使用其他语言时也会遇到同样的问题,因此您需要为它们命名。
-
好的 @Aaryan,也发布你的 Class 模型。
标签: php laravel eloquent relationship laravel-5.7