skip to Main Content

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


  1. These are positional arguments, where the 2nd is foreign key, the 3rd is local key:

    return $this->belongsTo(JournalHead::class, 'journal_head_id');
    

    Here’s the documentation.

    Login or Signup to reply.
  2. no need to type foreign key before journal_head_id..
    try like this:

    public function getEditorialHead() {
            return $this->belongsTo(JournalHead::class,  'journal_head_id');
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search