| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Models; |
| 4 |
|
| 5 |
class BookingActivity extends Model |
| 6 |
{ |
| 7 |
const TYPE_NOTE = 'note'; |
| 8 |
|
| 9 |
protected $table = 'fcal_booking_activity'; |
| 10 |
|
| 11 |
protected $guarded = ['id']; |
| 12 |
|
| 13 |
protected $fillable = [ |
| 14 |
'booking_id', |
| 15 |
'parent_id', |
| 16 |
'created_by', |
| 17 |
'status', |
| 18 |
'type', |
| 19 |
'title', |
| 20 |
'description' |
| 21 |
]; |
| 22 |
|
| 23 |
public static function boot() |
| 24 |
{ |
| 25 |
parent::boot(); |
| 26 |
|
| 27 |
static::creating(function ($model) { |
| 28 |
if (!isset($model->created_by) && $userId = get_current_user_id()) { |
| 29 |
$model->created_by = $userId; |
| 30 |
} |
| 31 |
}); |
| 32 |
} |
| 33 |
|
| 34 |
public function booking() |
| 35 |
{ |
| 36 |
return $this->belongsTo(Booking::class, 'booking_id'); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Host notes only. System rows stay on the unscoped relation, so a note |
| 41 |
* query cannot rewrite an email log or a cancellation reason. |
| 42 |
* |
| 43 |
* @param \FluentBooking\Framework\Database\Query\Builder $query |
| 44 |
* @return \FluentBooking\Framework\Database\Query\Builder |
| 45 |
*/ |
| 46 |
public function scopeNotes($query) |
| 47 |
{ |
| 48 |
return $query->where('type', self::TYPE_NOTE); |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|