環境:
- Laravel版本: 5.8.29
- PHP版本
$ php --version: PHP 7.2.24 (cli) 。
- 資料庫驅動& 版本
$ 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".
},
問題宣告:
下面的關系在localhost上作業,但在服務器上拋出了錯誤。這似乎是Doctrine/Inflector軟體包的問題。
注意:它在Localhost上作業,但在服務器設定上不作業。
$ php artisan tinker
>>> $borrower = Borrower::with('application')-> find(2) 。
PHP廢棄了。 "Doctrine/Common/Inflector/Inflector::pluralize"方法已被廢棄 并且將在doctrine/inflector 2.0中被放棄。請更新到新的Inflector API。 in /path/vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php on line 264
Illuminate/Database/Eloquent/RelationationNotFoundException,資訊'呼叫模型[App/Borrower]上未定義的關系[application]'。
模塊
AppBorrower.php
<?php
namespace App。
使用 IlluminateFoundationAuthUser as Authenticatable;
class Borrower extends Authenticatable
{
protected $table = '借款人'。
public function application()
{
return $this-> hasMany('AppModelsApplication', '借款人_id', '借款人_id')。
}
AppModelsApplication.php
<?php
namespace AppModels。
使用 IlluminateDatabaseEloquentModel。
class Application extends Model
{
protected $table = 'apps'。
public function borrower()
{
return $this-> belongsTo('AppBorrower', 'borrower_id', '借款人_id')。
}
表
借款人
| borrower_id | fname | email | |
|-------------|--------|------------------------|
| 1 | John | [email protected] |
| 2 | Thomas | [email protected] |
應用
| id | name | borrower_id | |
|----|------------|-------------|
| 1 | Birmingham | 1 !
| 2 | BBC | 1 !
uj5u.com熱心網友回復:
問題出在教義轉折點方法上, 也許你需要升級它, 否則其他的解決方案是將你的Laravel版本升級到至少7.x.
.嘗試在你的命令列中升級你的包的版本:
composer update
然后安裝新的教義/inflector:
composer require doctrine/inflector
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/331372.html
標籤:
