This commit is contained in:
@@ -51,4 +51,19 @@ class Bot extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(BotLog::class);
|
||||
}
|
||||
|
||||
public function latestLog()
|
||||
{
|
||||
return $this->hasOne(BotLog::class)->latestOfMany();
|
||||
}
|
||||
|
||||
public function failedLogs()
|
||||
{
|
||||
return $this->hasMany(BotLog::class)->where('status', 'failed');
|
||||
}
|
||||
}
|
||||
|
||||
30
app/Models/BotLog.php
Normal file
30
app/Models/BotLog.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BotLog extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'bot_id',
|
||||
'started_at',
|
||||
'finished_at',
|
||||
'status',
|
||||
'output',
|
||||
'error',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function bot()
|
||||
{
|
||||
return $this->belongsTo(Bot::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user