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

[BUG] Accessor method for parent_id on model App\Modules\ProductCatalog\Models\Category does not exist #55

Open
fbarrento opened this issue May 21, 2023 · 2 comments
Labels
bug Something isn't working Stale

Comments

@fbarrento
Copy link

What happened?

When running vendor/bin/sail artisan model:typer --plurals --api-resources modeltyper return this error:

 Exception 

  Accessor method for parent_id on model App\Modules\ProductCatalog\Models\Category does not exist

  at vendor/fumeapp/modeltyper/src/Actions/DetermineAccessorType.php:38
     34▕             return $reflectionModel->getMethod($method);
     35▕         } catch (Exception $e) {
     36▕         }
     37▕ 
  ➜  38▕         throw new Exception('Accessor method for ' . $mutator . ' on model ' . $reflectionModel->getName() . ' does not exist');
     39▕     }
     40▕ }
     41▕ 

      +21 vendor frames 

  22  artisan:35
      Illuminate\Foundation\Console\Kernel::handle()

I'm using NestedSet Package to manage the categories.

And applying the trait on the categories model.

<?php

namespace App\Modules\ProductCatalog\Models;

use Kalnoy\Nestedset\NodeTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Category extends Model
{
    use HasFactory;
    use NodeTrait;

    public $level;

    public $fillable = [
        'name',
        'slug',
        'parent_id',
        'description'
    ];

    public function products(): HasMany
    {
        return $this->hasMany(Product::class);
    }

}

Environment:
laravel: 10
database: postgres

Expected Behavior

The expected behavior is the output of TypeScript interfaces declarations on the console.

Steps To Reproduce

  1. run vendor/bin/sail artisan model:typer --plurals --api-resources
  2. View error
@fbarrento fbarrento added the bug Something isn't working label May 21, 2023
@tcampbPPU
Copy link
Member

This exception is supposed to throw when it cannot determine either accessors/mutator method, think like

public function getParentAttribute(): ?self
{
    return $this->where('id', $this->parent_id)->first();
}

or

protected function parent(): Attribute
{
    return Attribute::make(
        get: fn() => $this->where('id', $this->parent_id)->first();
    );
}

Which in your case looks like its coming from that NodeTrait so I would have to see whats all in that trait.
When you run the Laravel Model Show command what is the output for this model?

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants