aboutsummaryrefslogtreecommitdiff
path: root/app/Models/BookmarkCategory.php
blob: a8bc8d2611723ea5ac8b23fcd7b36db64c102984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BookmarkCategory extends Model
{
    use HasFactory;
    protected $table = "bookmark__categories";
    protected $fillable = ['name'];

    public function sites() {
        return $this->hasMany(BookmarkSite::class, 'category');
    }

    public static function insertBookmarkCategory(string $name) {
        $newBookmarkCategory = new BookmarkCategory;
        $newBookmarkCategory->name = $name;
        $newBookmarkCategory->save();
    }
    public static function selectBookmarks(int $id) {
        $bookmarks = BookmarkSite::where('category', '=', $id)->firstOrFail();
        return $bookmarks;
    }

    public static function importBookmarkCategory(array $data) {
        foreach ($data as $category) {
            $newBookmarkCategory = new BookmarkCategory;
            $newBookmarkCategory->name = $category['name'];
            $newBookmarkCategory->priority = intval($category['priority']);
            $newBookmarkCategory->save();
        }
    }
}