2024-07-23 15:22:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-07-23 16:40:56 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-07-23 15:22:09 +00:00
|
|
|
|
|
|
|
class Tool extends Model
|
|
|
|
{
|
2024-07-23 16:40:56 +00:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'url',
|
|
|
|
'api_key',
|
|
|
|
'callback_url',
|
|
|
|
'user_id',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function functions(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(ToolFunction::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fetchFunctions(): void
|
|
|
|
{
|
|
|
|
$url = $this->url;
|
|
|
|
|
|
|
|
$json = Http::get($url);
|
|
|
|
|
|
|
|
$json = $json->json();
|
|
|
|
|
|
|
|
$this->callback_url = $json['callback_url'];
|
|
|
|
|
|
|
|
}
|
2024-07-23 15:22:09 +00:00
|
|
|
}
|