samedi 21 août 2021

Call to undefined relationship [relation] on model [App/Model]

Environment:

  • Laravel Version: 5.7.29
  • PHP Version $ php --version: PHP 7.2.24 (cli)
  • Database Driver & Version $ mysql --version: mysql Ver 8.0.23-0ubuntu0.20.04.1
  • Doctrine/Inflector: 1.4.4

composer.json

    "require": {
        "php": ">=7.2.24",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "~1.0",
        "doctrine/inflector": "1.4.4"
    },

Problem Statement:

Below relation is working on localhost but throwing error on Server. This seems like issue is with Doctrine/Inflector package.

$ php artisan tinker
>>> $borrower = Borrower::with('application')->find(2);

PHP Deprecated:  The "Doctrine/Common/Inflector/Inflector::pluralize" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API. in /path/vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php on line 264
Illuminate/Database/Eloquent/RelationNotFoundException with message 'Call to undefined relationship [application] on model [App/Borrower].'

Models

App\Borrower.php

<?php  

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class Borrower extends Authenticatable
{

    protected $table = 'borrowers';

    public function application()
    {
        return $this->hasMany('App\Models\Application', 'borrower_id', 'borrower_id');
    }

App\Models\Application.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Application extends Model
{
    
    protected $table = 'applications';

    public function borrower()
    {
        return $this->belongsTo('App\Borrower', 'borrower_id', 'borrower_id');
    }

Table


borrowers

| borrower_id | fname  | email                  |
|-------------|--------|------------------------|
| 1           | John   | john@peakyblinder.com  |
| 2           | Thomas | tommy@peakyblinder.com |

applications

| id | name       | borrower_id |
|----|------------|-------------|
| 1  | Birmingham | 1           |
| 2  | BBC        | 1           |



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire