2018-05-09 08:05:17 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-03-31 17:28:47 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2018-05-09 08:05:17 -05:00
|
|
|
|
|
|
|
|
class Dashboard extends Model
|
|
|
|
|
{
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
protected $primaryKey = 'dashboard_id';
|
|
|
|
|
protected $fillable = ['user_id', 'dashboard_name', 'access'];
|
|
|
|
|
|
|
|
|
|
// ---- Query scopes ----
|
|
|
|
|
|
|
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Builder $query
|
|
|
|
|
* @param User $user
|
2018-05-09 08:05:17 -05:00
|
|
|
* @return Builder|static
|
|
|
|
|
*/
|
|
|
|
|
public function scopeAllAvailable(Builder $query, $user)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('user_id', $user->user_id)
|
|
|
|
|
->orWhere('access', '>', 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
// ---- Define Relationships ----
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2021-03-31 17:28:47 +02:00
|
|
|
public function user(): BelongsTo
|
2018-05-09 08:05:17 -05:00
|
|
|
{
|
2020-04-21 14:28:48 +02:00
|
|
|
return $this->belongsTo(\App\Models\User::class, 'user_id');
|
2018-05-09 08:05:17 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-31 17:28:47 +02:00
|
|
|
public function widgets(): HasMany
|
2018-05-09 08:05:17 -05:00
|
|
|
{
|
2020-04-21 14:28:48 +02:00
|
|
|
return $this->hasMany(\App\Models\UserWidget::class, 'dashboard_id');
|
2018-05-09 08:05:17 -05:00
|
|
|
}
|
|
|
|
|
}
|