-1

我浏览了这篇文章... Laravel - 使用保留字命名模型

但这并没有提供定义关系的解决方案。

我有一个模型名称Class.php ,我必须将它与 Student & ClassAllocation 联系起来

这是我在 Student.php 中定义的关系:

/**
 * Check the Class allocated to Student
 *
 *@return void
 */
public function class()
{
    return $this->belongsToMany('App\Class', 'class_allocations');
}

我已经尝试了所有方法,现在我不想更改我的模型名称。我该如何进行这项工作?我在修补程序上不断收到此错误:

PHP 错误:语法错误,意外的“类”(T_CLASS),第 7 行 /home/vagrant/Homestead/app/app/Class.php 中的预期标识符(T_STRING)

4

1 回答 1

0

你不能使用保留字!!!!

作为一个建议(我在我的项目中所做的)是使用模型“ClassRoom”或其他东西的名称。

以及关系“classRooms()”之类的名称。

于 2018-09-27T16:45:21.210 回答