141 lines
4.6 KiB
PHP
141 lines
4.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class Homeparty
|
|
*
|
|
* @property int $id
|
|
* @property Carbon $date
|
|
* @property string $name
|
|
* @property string $place
|
|
* @property string $description
|
|
* @property int $pos
|
|
* @property int $completed
|
|
* @property int $status
|
|
* @property bool $order_to
|
|
* @property bool $active
|
|
* @property bool $default
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property Collection|User[] $users
|
|
* @package App\Models
|
|
* @property int|null $auth_user_id
|
|
* @property-read \App\User|null $auth_user
|
|
* @property-read \App\Models\HomepartyUser|null $homeparty_host
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\HomepartyUser[] $homeparty_users
|
|
* @property-read int|null $homeparty_users_count
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereAuthUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereCompleted($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereDefault($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereDescription($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereOrderTo($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty wherePlace($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty wherePos($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereStatus($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @property string|null $token
|
|
* @property bool|null $token_active
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\HomepartyUser[] $homeparty_guests
|
|
* @property-read int|null $homeparty_guests_count
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Homeparty whereTokenActive($value)
|
|
*/
|
|
class Homeparty extends Model
|
|
{
|
|
protected $table = 'homeparties';
|
|
|
|
protected $casts = [
|
|
'pos' => 'int',
|
|
'completed' => 'int',
|
|
'status' => 'int',
|
|
'order_to' => 'bool',
|
|
'active' => 'bool',
|
|
'default' => 'bool',
|
|
'token_active' => 'bool',
|
|
'settings' => 'array',
|
|
'order' => 'array'
|
|
];
|
|
|
|
protected $dates = [
|
|
'date'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'token'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'auth_user_id',
|
|
'date',
|
|
'name',
|
|
'place',
|
|
'description',
|
|
'pos',
|
|
'completed',
|
|
'status',
|
|
'order_to',
|
|
'active',
|
|
'default',
|
|
'token',
|
|
'token_active',
|
|
'settings',
|
|
'order'
|
|
];
|
|
|
|
public function auth_user()
|
|
{
|
|
return $this->belongsTo('App\User', 'auth_user_id');
|
|
}
|
|
|
|
public function homeparty_users()
|
|
{
|
|
return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id');
|
|
}
|
|
|
|
public function homeparty_host()
|
|
{
|
|
return $this->hasOne('App\Models\HomepartyUser', 'homeparty_id')->where('is_host', true);
|
|
}
|
|
|
|
public function homeparty_guests()
|
|
{
|
|
return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id')->where('is_host', false);
|
|
}
|
|
|
|
|
|
public function getDateAttribute($value)
|
|
{
|
|
if (!$value) {
|
|
return "";
|
|
}
|
|
return Carbon::parse($value)->format(\Util::formatDateDB());
|
|
}
|
|
|
|
public function setDateAttribute($value)
|
|
{
|
|
$this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
|
}
|
|
|
|
public function getTokenLink(){
|
|
return url('homeparty/'.$this->token);
|
|
}
|
|
}
|
|
|