Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of class_basename cause to use wrong PHP class #130

Open
bastos71 opened this issue Jun 7, 2024 · 0 comments
Open

Usage of class_basename cause to use wrong PHP class #130

bastos71 opened this issue Jun 7, 2024 · 0 comments

Comments

@bastos71
Copy link

bastos71 commented Jun 7, 2024

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

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 :

> \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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant