I am using Laravel 8 and i uploaded my project to cPanel. In my local server it works fine but in live server it show me error:
syntax error, unexpected ‘:’, expecting ‘)’ on
return $this->belongsTo(JournalHead::class, foreignKey: ‘journal_head_id’);
Below is my model:
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
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');
}
}
2
Answers
These are positional arguments, where the 2nd is foreign key, the 3rd is local key:
Here’s the documentation.
no need to type foreign key before journal_head_id..
try like this: