69 lines
1.4 KiB
PHP
69 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Panier extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $appends = array('mediacount', 'mediacover');
|
|
|
|
/**
|
|
* Get the user that owns the panier.
|
|
*/
|
|
public function owner()
|
|
{
|
|
return $this->belongsTo('App\User', 'owner');
|
|
}
|
|
|
|
/**
|
|
* The users that belong to the panier.
|
|
*/
|
|
public function usersFavoris()
|
|
{
|
|
return $this->belongsToMany('App\User', 'paniers_users', 'panier_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* The medias that belong to the panier.
|
|
*/
|
|
public function medias()
|
|
{
|
|
return $this->belongsToMany('App\Media', 'paniers_medias', 'panier_id', 'media_id');
|
|
}
|
|
|
|
/**
|
|
* Get media linked
|
|
*/
|
|
public function getMediacountAttribute()
|
|
{
|
|
return $this->medias()->count();
|
|
}
|
|
|
|
/**
|
|
* Get media linked
|
|
*/
|
|
public function getMediacoverAttribute()
|
|
{
|
|
$cover = "";
|
|
$media = $this->medias()->where('typemedia_id', 1)->first();
|
|
if($media){
|
|
switch ($media->typemedia_id) {
|
|
case 1:
|
|
if($media->extension == "pdf" || $media->extension == "ai" || $media->extension == "psd"){
|
|
$cover = $media->folder.$media->uid."_thumb.png";
|
|
}else{
|
|
$cover = $media->folder.$media->uid."_thumb.".$media->extension;
|
|
}
|
|
break;
|
|
case 2:
|
|
$cover = $media->folder.$media->uid."_thumb.".$media->extension;
|
|
break;
|
|
}
|
|
}
|
|
return $cover;
|
|
}
|
|
}
|