Environment:
- Laravel Version: 5.8.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
composer.json
"require": {
"php": ">=7.2.24",
"fideloper/proxy": "~4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "~1.0",
"doctrine/inflector": "1.4.0"
},
Problem Statement:
Below relation is working on localhost but throwing error on Server. This seems like issue is with Doctrine/Inflector package.
Note: Its working on Localhost but not on server setup.
$ 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 | [email protected] |
| 2 | Thomas | [email protected] |
applications
| id | name | borrower_id |
|----|------------|-------------|
| 1 | Birmingham | 1 |
| 2 | BBC | 1 |
CodePudding user response:
The problem is that the doctrine inflector method, maybe you need upgrade it otherwise other solution is upgrade your version of Laravel to at least 7.x.
Try to upgrade your version of your packages in your command line:
composer update
and then install the new doctrine/inflector:
composer require doctrine/inflector