psalm-plugin-laravel/tests/Models/User.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2022-01-19 23:05:35 +01:00
<?php
declare(strict_types=1);
namespace Tests\Psalm\LaravelPlugin\Models;
2021-07-06 12:34:11 +02:00
use Carbon\CarbonInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
2021-06-14 22:26:51 +02:00
/**
* @property string $id
2021-07-06 12:34:11 +02:00
* @property CarbonInterface|null $email_verified_at
2021-06-14 22:26:51 +02:00
*/
2022-01-19 23:05:35 +01:00
final class User extends Model
{
protected $table = 'users';
/**
* @psalm-return HasOne<Phone>
*/
public function phone(): HasOne
{
return $this->hasOne(Phone::class);
}
/**
* @psalm-return BelongsToMany<Role>
*/
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
/**
* @psalm-return HasManyThrough<Mechanic>
*/
public function carsAtMechanic(): HasManyThrough
{
return $this->hasManyThrough(Mechanic::class, Car::class);
}
/**
* Get the user's image.
*/
public function image()
{
return $this->morphOne(Image::Class, 'imageable');
}
2021-07-04 19:51:08 +02:00
/**
* Scope a query to only include active users.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeActive($query)
{
return $query->where('active', 1);
}
}