Skip to content

Commit

Permalink
User model configuration (#8)
Browse files Browse the repository at this point in the history
* Update filament-bookmarks-menu.php

Added option for user_model

* Update BookmarksMenuResource.php

Added conditional User Model

* Update BookmarksMenu.php

Added conditional User Model

* Update BookmarksMenuResource.php

* Update create_filament_bookmarks_menu_table.php.stub
  • Loading branch information
fetova authored Jun 3, 2023
1 parent 50e22f9 commit b48b7a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/filament-bookmarks-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
'delete_text_class' => 'cursor-pointer text-white bg-black dark:text-gray-200',
'show_private_label_in_menu' => false,
'show_global_label_in_menu' => false,
'user_model' => env('USER_MODEL',App\Models\User::class)
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\User;

return new class extends Migration
{
public function up()
{
Schema::create('filament_bookmarks_menu_table', function (Blueprint $table) {
$userModel = config('filament-bookmarks-menu.user_model', User::class);
$table->id();
$table->string('menu_label');
$table->string('menu_url');
$table->string('menu_target')->default('_self')->nullable();
$table->integer('sort_order')->default(0);
$table->foreignIdFor(\App\Models\User::class, 'menu_user_id')->nullable();
$table->foreignIdFor($userModel, 'menu_user_id')->nullable();
$table->timestamps();
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/Models/BookmarksMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;

class BookmarksMenu extends Model
{
Expand All @@ -12,6 +13,7 @@ class BookmarksMenu extends Model
protected $table = "filament_bookmarks_menu_table";

public function user() {
return $this->belongsTo(\App\Models\User::class, 'menu_user_id', 'id');
$userModel = config('filament-bookmarks-menu.user_model', User::class);
return $this->belongsTo($userModel, 'menu_user_id', 'id');
}
}
3 changes: 2 additions & 1 deletion src/Resources/BookmarksMenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected static function shouldRegisterNavigation(): bool
}
public static function form(Form $form): Form
{
$userModel = config('filament-bookmarks-menu.user_model', User::class);
return $form
->schema([
Card::make()
Expand All @@ -42,7 +43,7 @@ public static function form(Form $form): Form
->label(__('filament-bookmarks-menu::filament-bookmarks-menu.resource.form.target')),
Forms\Components\TextInput::make('sort_order')->required()->numeric()->label(__('filament-bookmarks-menu::filament-bookmarks-menu.resource.form.sort_order'))->default(0),
Forms\Components\Select::make('menu_user_id')->nullable()->label(__('filament-bookmarks-menu::filament-bookmarks-menu.resource.form.user'))->options(
User::all()->pluck('name', 'id')
$userModel::all()->pluck('name', 'id')
)->placeholder(__('filament-bookmarks-menu::filament-bookmarks-menu.resource.form.user.placeholder.label')),
])
]);
Expand Down

0 comments on commit b48b7a0

Please sign in to comment.