ldc-dam/app/Models/Panier.php
Jérémy Munsch 9767e62c72
Update NPM deps and webpack.mix.js
composer require ldc/web-status-checker-laravel remove Old static status checker

Fix ImportMedia

WIP commands OK

many fixes

Fix and try to optimize folder component

Fix front icons + actions based on icons

Favico

front fix alert

Fix Media upload on depot

fix folder component buttons

Full front fix with perf due tu vuejs

Download medias

Navigate within medias superfix

Move media + loader

isLocked boolean and remove media fix

Folder scroll fix

arcadia link color red

Fix panier show external

Tons of fixes back as front

REwrited all
2022-07-22 17:00:48 +02:00

103 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Panier extends Model
{
use SoftDeletes;
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [
'mediacount', 'mediacover'
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'description', 'libelle', 'statut'
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'statut' => 'boolean'
];
// * RELATIONSHIPS
/**
* BelongsTo user relation
* Get the user that owns the panier.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function owner()
{
return $this->belongsTo(User::class, 'user_id');
}
/**
* BelongsToMany users relation
* The users that belong to the panier.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function usersFavoris()
{
return $this->belongsToMany(User::class);
}
/**
* BelongsToMany mediaList relation
* The mediaList that belong to the panier.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function mediaList()
{
return $this->belongsToMany(Media::class, 'panier_media');
}
// * GETTERS
/**
* Get mediacount attribute
*
* @return boolean
*/
public function getMediacountAttribute(): int
{
return $this->mediaList()->count();
}
/**
* Get mediacover attribute
*
* @return string
*/
public function getMediacoverAttribute(): string
{
$media = $this->mediaList()->whereHas('typeMedia', function ($q) {
// * Where type is Photo
$q->where('codeTypemedia', 1);
})->first();
if ($media) {
return $media->thumb_relative_path;
}
return '';
}
}