ITADN

Usage of class_basename cause to use wrong PHP class

#130Openbastos71 创建于 2024-06-07
B
bastos71commented
In `getClassNameForRelationships` methods, usage of `class_basename` allows to get the class without the FQN, causing an issue when multiple classes are called with the same base name in the project. Example : * model classes * `App\Models\Product` <- Parent * `App\Models\ProductPack` <- Child * `App\Models\ProductSimple` <- Child * resource class `App\Http\Resources\Product` * creating this relation : ```php <?php namespace App\Models; use App\Models\Interfaces\ProductInterface; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Parental\HasParent; class ProductPack extends Product implements ProductInterface { use HasParent; public const TYPE = 'pack'; public function containedProducts(): BelongsToMany { return $this->belongsToMany(ProductSimple::class); } } ``` Testing in tinker will output this error : ```shell > \App\Models\ProductPack::first()->containedProducts; [!] Aliasing 'Product' to 'App\Http\Resources\Product' for this Tinker session. ArgumentCountError Too few arguments to function Illuminate\Http\Resources\Json\JsonResource::__construct(), 0 passed in vendor/tightenco/parental/src/HasParent.php on line 78 and exactly 1 expected. ```
0 条评论