38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BookmarkCategory extends Model
|
|
{
|
|
use HasFactory;
|
|
protected $table = "bookmark__categories";
|
|
protected $fillable = ['name', 'shuffled'];
|
|
protected $casts = ['shuffled' => 'boolean'];
|
|
|
|
public function sites() {
|
|
return $this->hasMany(BookmarkSite::class, 'category');
|
|
}
|
|
|
|
public static function create(Request $request): BookmarkCategory {
|
|
$newCategory = new BookmarkCategory();
|
|
$newCategory->name = $request->get('name');
|
|
$newCategory->shuffled = $request->has('shuffled');
|
|
$newCategory->save();
|
|
return $newCategory;
|
|
}
|
|
|
|
|
|
public static function insertBookmarkCategory(string $name): void {
|
|
$newBookmarkCategory = new BookmarkCategory;
|
|
$newBookmarkCategory->name = $name;
|
|
$newBookmarkCategory->save();
|
|
}
|
|
public static function selectBookmarks(int $id) {
|
|
$bookmarks = BookmarkSite::where('category', '=', $id)->firstOrFail();
|
|
return $bookmarks;
|
|
}
|
|
}
|