*/ protected $fillable = [ 'content', 'type', 'claim_id', 'user_id', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => ClaimMessageType::class, ]; // * RELATIONS /** * Claim belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function claim(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Claim::class); } /** * User belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(User::class); } // * METHODS /** * Get all messages from a specific claim. * * @param integer $claimModelKey * @return \Illuminate\Database\Eloquent\Collection */ public static function getAllClaimMessages(int $claimModelKey): \Illuminate\Database\Eloquent\Collection { return self::query() ->with('user') ->whereHas('claim', fn($q) => $q->whereKey($claimModelKey)) ->orderby('created_at', 'ASC') ->get(); } }