diff options
Diffstat (limited to 'app/Models/BookmarkSite.php')
-rw-r--r-- | app/Models/BookmarkSite.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/Models/BookmarkSite.php b/app/Models/BookmarkSite.php new file mode 100644 index 0000000..3c9cc5d --- /dev/null +++ b/app/Models/BookmarkSite.php @@ -0,0 +1,35 @@ +<?php + +namespace App\Models; + +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; + +class BookmarkSite extends Model { + use HasFactory; + protected $table = "bookmark__sites"; + protected $fillable = ['name', 'description', 'url', 'category']; + + public function category() { + return $this->belongsTo(BookmarkCategory::class, 'category'); + } + public static function insertBookmark(string $name, string $url, int $category) { + $category = BookmarkCategory::where('id', $category)->firstOrFail(); + $newBookmark = new BookmarkSite; + $newBookmark->name = $name; + $newBookmark->url = $url; + $newBookmark->category = $category->id; + $newBookmark->save(); + } + + public static function importBookmark(array $data) { + foreach ($data as $site) { + $newBookmark = new BookmarkSite; + $newBookmark->name = $site['name']; + $newBookmark->description = $site['description']; + $newBookmark->url = $site['url']; + $newBookmark->category = $site['category_id']; + $newBookmark->save(); + } + } +} |