plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request]: Support for pivot values in models

Open abenerd opened this issue 3 years ago • 0 comments

Feature Description

<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    public function companies(): BelongsToMany
    {
        return $this->belongsToMany(Company::class)->withPivot(['role']);
    }
}
<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Company extends Model
{
    public function members(): BelongsToMany
    {
        return $this->belongsToMany(User::class)->withPivot(['role']);
    }
}

Say you have a relationship between two tables like these, when I now find a user via the company or vise versa I would love to be able to autocomplete the pivot values.


Company::query()->first()->members()->find(3)->pivot->role;

Ist it possible to autocomplete the last part, the ->pivot->role part when generating the helper code for the models?

abenerd avatar Aug 18 '22 08:08 abenerd