43 lines
801 B
PHP
43 lines
801 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class Tool extends Model
|
|
{
|
|
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'];
|
|
|
|
}
|
|
}
|