105 lines
2.9 KiB
PHP
105 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class BookingNotice
|
|
*
|
|
* @property int $id
|
|
* @property int $booking_id
|
|
* @property int $from_user_id
|
|
* @property int $to_user_id
|
|
* @property string $message
|
|
* @property bool $show
|
|
* @property bool $important
|
|
* @property Carbon $edit_at
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property Booking $booking
|
|
* @property User $user
|
|
* @package App\Models
|
|
* @property-read \App\User $from_user
|
|
* @property-read \App\User|null $to_user
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereBookingId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereEditAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereFromUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereImportant($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereMessage($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereShow($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereToUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingNotice whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class BookingNotice extends Model
|
|
{
|
|
protected $table = 'booking_notices';
|
|
|
|
protected $casts = [
|
|
'booking_id' => 'int',
|
|
'from_user_id' => 'int',
|
|
'to_user_id' => 'int',
|
|
'show' => 'bool',
|
|
'important' => 'bool'
|
|
];
|
|
|
|
protected $dates = [
|
|
'edit_at',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'booking_id',
|
|
'from_user_id',
|
|
'to_user_id',
|
|
'message',
|
|
'show',
|
|
'important',
|
|
'edit_at'
|
|
];
|
|
|
|
public function booking()
|
|
{
|
|
return $this->belongsTo(Booking::class);
|
|
}
|
|
|
|
public function to_user()
|
|
{
|
|
return $this->belongsTo(User::class, 'to_user_id');
|
|
}
|
|
|
|
public function from_user()
|
|
{
|
|
return $this->belongsTo(User::class, 'from_user_id');
|
|
}
|
|
|
|
public function getName(){
|
|
if($this->from_user){
|
|
if($this->from_user->sf_guard_user){
|
|
return $this->from_user->sf_guard_user->first_name." ".$this->from_user->sf_guard_user->last_name;
|
|
}else{
|
|
$this->from_user->name;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getSmallerMessage($max = 500){
|
|
|
|
$ret = substr($this->message, 0, $max);
|
|
if(strlen($this->message) > 500){
|
|
$ret .= " ...";
|
|
}
|
|
return $ret;
|
|
}
|
|
}
|