Files
aibuddytool/app/Models/AiTool.php
2023-11-28 04:39:36 +08:00

101 lines
2.3 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
/**
* Class AiTool
*
* @property int $id
* @property int $category_id
* @property int $url_to_crawl_id
* @property string|null $screenshot_img
* @property bool $is_ai_tool
* @property string $tool_name
* @property string $is_app_web_both
* @property string|null $tagline
* @property string|null $summary
* @property string $pricing_type
* @property string|null $keyword_string
* @property string|null $qna
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Category $category
* @property UrlToCrawl $url_to_crawl
* @property Collection|SearchEmbedding[] $search_embeddings
* @property Collection|AiToolKeyword[] $ai_tool_keywords
*/
class AiTool extends Model
{
protected $table = 'ai_tools';
protected $casts = [
'category_id' => 'int',
'url_to_crawl_id' => 'int',
'view_count' => 'int',
'is_ai_tool' => 'bool',
'qna' => 'object',
];
protected $fillable = [
'category_id',
'url_to_crawl_id',
'screenshot_img',
'is_ai_tool',
'tool_name',
'slug',
'is_app_web_both',
'tagline',
'summary',
'pricing_type',
'keyword_string',
'view_count',
'qna',
'external_url
',
];
protected function screenshotImg(): Attribute
{
return Attribute::make(
get: function ($value = null) {
if (! is_empty($value)) {
return Storage::disk(config('platform.uploads.ai_tools.screenshot.driver'))->url(config('platform.uploads.ai_tools.screenshot.path').$value);
}
return null;
}
);
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function url_to_crawl()
{
return $this->belongsTo(UrlToCrawl::class);
}
public function search_embeddings()
{
return $this->hasMany(SearchEmbedding::class);
}
public function keywords()
{
return $this->hasMany(AiToolKeyword::class);
}
}