【问题标题】:I uploaded my Laravel 8 project to Cpanel while i got an error我将 Laravel 8 项目上传到 Cpanel 时出现错误
【发布时间】: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');
    }

}

【问题讨论】:

标签: php eloquent laravel-8


【解决方案1】:

这些是位置参数,其中第二个是外键,第三个是本地键:

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

这是documentation

【讨论】:

    【解决方案2】:

    不需要在 journal_head_id 之前输入外键。 试试这样:

    public function getEditorialHead() {
            return $this->belongsTo(JournalHead::class,  'journal_head_id');
        }
    

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 2019-02-04
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 2021-06-03
      • 2017-01-16
      • 1970-01-01
      • 2017-02-21
      相关资源
      最近更新 更多