-
app/Models/Concerns/ManagesPeerships.php
Open in GitHubuse App\Models\User; use App\Models\Peership; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany; trait ManagesPeerships { public function peersOfThisUser(): BelongsToMany { return $this->belongsToMany(User::class, 'peerships', 'first_user_id', 'second_user_id') ->withPivot('status') ->wherePivot('status', 'accepted'); } // public function peer_requests(): HasMany { return $this->hasMany(Peership::class, 'second_user_id') ->where('status', 'pending'); } // }
-
app/Models/User.php
Open in GitHubuse App\Models\Concerns\ManagesPeerships; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { // use ManagesPeerships; // }
-
app/Http/Livewire/Dashboard/Panels/ManagePeerRequestsPanel.php
Open in GitHubuse Livewire\Component; use Illuminate\Database\Eloquent\Collection; class ManagePeerRequestsPanel extends Component { public Collection $requests; // public function queryRequests() { $this->requests = auth()->user() ->load(['peer_requests', 'peer_requests.sender']) ->peer_requests; } // }