【发布时间】:2021-08-25 09:40:26
【问题描述】:
我正在使用 Laravel 8 并将我的项目上传到 cPanel。在我的本地服务器中它工作正常,但在实时服务器中它显示错误:
语法错误,意外 ':',期待 ')' on
return $this->belongsTo(JournalHead::class, foreignKey: 'journal_head_id');
下面是我的模型:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class JournalEditorial extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'journal_head_id',
'editorial_title',
'editorial_author',
'abstract',
'editorial_page_no',
'editorial_pdf_file',
'editorial_doi_link',
];
public function getEditorialHead() {
return $this->belongsTo(JournalHead::class, foreignKey: 'journal_head_id');
}
}
【问题讨论】:
-
foreignKey: 'journal_head_id'不是有效的 PHP 语法。我认为您需要将关联数组作为第二个参数php.net/manual/en/language.types.array.php