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

Relations not shown in artisan command model:show #206

Closed
cpuch opened this issue Sep 19, 2023 · 3 comments
Closed

Relations not shown in artisan command model:show #206

cpuch opened this issue Sep 19, 2023 · 3 comments

Comments

@cpuch
Copy link

cpuch commented Sep 19, 2023

Hello,

I have a Client model with a HasManyDeep relation as follow

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
use App\Models\ListItem;
use App\Models\RoyaltiesArtist;
use App\Models\RoyaltiesContrat;

class Client extends Model
{
    use HasFactory;
    use \Staudenmeir\EloquentHasManyDeep\HasRelationships;

    [...]

    public function artistContracts(): HasManyDeep
    {
        return $this->hasManyDeep(
            RoyaltiesContrat::class,
            [RoyaltiesArtist::class, ListItem::class], // Intermediate models, beginning at the far parent (Client).
            [
                'id_client',          // Foreign key on the royalties_artist table.
                'id_item',            // Foreign key on the list_item table.
                'id_list_info_artist' // Foreign key on the royalties_contrat table.
            ],
            [
                'id_client', // Local key on the client table.
                'id',        // Local key on the royalties_artist table.
                'id_list',   // Local key on the list_item table.
            ]
        );
    }

    [...]
}

When I use the artisan command the relation is not displayed

 php artisan model:show Client

  App\Models\Client ................................................................................................................................
  Database .............................................................................................................................. soundworks
  Table ..................................................................................................................................... client

  Attributes ........................................................................................................................... type / cast
  id_client increments, unique .............................................................................................. integer unsigned / int

  [...]

  Relations ........................................................................................................................................
  password HasOne .............................................................................................................. App\Models\Password
  artist HasOne ......................................................................................................... App\Models\RoyaltiesArtist
  bands HasMany ........................................................................................................... App\Models\RoyaltiesBand
  bandContracts HasManyThrough ......................................................................................... App\Models\RoyaltiesContrat

  Observers ........................................................................................................................................

It would be nice if the artisan command could return the relationship.

@staudenmeir
Copy link
Owner

Hi @cpuch,
The model:show command doesn't support custom relations like HasManyDeep and doesn't have a way to add them.

This needs to be changed in Laravel. I'll look into submitting a PR when I find the time.

@staudenmeir staudenmeir added the enhancement New feature or request label Oct 17, 2023
@staudenmeir
Copy link
Owner

I have to close this issue. I've looked into it but I don't see a viable solution for the Laravel command to support third-party relations.

If you want/need to have this feature in your app, you can create your own model:show command by extending ShowModelCommand and overriding $relationMethods.

@staudenmeir staudenmeir removed the enhancement New feature or request label Dec 29, 2023
@staudenmeir
Copy link
Owner

@cpuch I revisited this topic and submitted a PR to Laravel that supports third-party relations when they have a return type (like yours do). It will part of the next Laravel 11 release.

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

2 participants