-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature to use menu as filament dashboard menu
- Loading branch information
Showing
14 changed files
with
509 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
return [ | ||
//You config go here... | ||
"locals" => [ | ||
"ar" => [ | ||
"ar" => "العربية", | ||
"en" => "الإنجليزية" | ||
], | ||
"en" => [ | ||
"ar" => "Arabic", | ||
"en" => "English" | ||
] | ||
] | ||
]; |
55 changes: 55 additions & 0 deletions
55
database/migrations/2024_05_13_192724_create_menu_items_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('menu_items', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('menu_id')->constrained()->onDelete('cascade'); | ||
|
||
//Item Title | ||
$table->json('title'); | ||
$table->string('icon')->default('primary')->nullable(); | ||
|
||
|
||
//Badge Options | ||
$table->string('badge_color')->nullable(); | ||
$table->boolean('has_badge')->default(1)->nullable(); | ||
$table->boolean('has_badge_query')->default(1)->nullable(); | ||
$table->string('badge_table')->nullable(); | ||
$table->string('badge_condation')->nullable(); | ||
$table->json('badge')->nullable(); | ||
|
||
//URL Options | ||
$table->boolean('is_route')->default(1)->nullable(); | ||
$table->string('route')->nullable(); | ||
$table->string('url')->nullable(); | ||
$table->boolean('new_tab')->nullable(); | ||
|
||
//Permissions | ||
$table->json('permissions')->nullable(); | ||
$table->integer('order')->default(0)->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('menu_items'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@php | ||
$record = \TomatoPHP\FilamentMenus\Models\MenuItem::find($getState()); | ||
@endphp | ||
<div class="flex justify-start gap-2"> | ||
@if(!empty($record->icon)) | ||
<x-icon :name="$record->icon" class="w-6 h-6"/> | ||
@endif | ||
<div> | ||
{{ $record->title[app()->getLocale()] }} | ||
</div> | ||
@if($record->has_badge) | ||
<div> | ||
<x-filament::badge :hidden="$record->has_badge"> | ||
{{ $record->badge[app()->getLocale()] }} | ||
</x-filament::badge> | ||
</div> | ||
@endif | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMenus\Models; | ||
|
||
use Filament\Resources\Concerns\Translatable; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class MenuItem extends Model | ||
{ | ||
use HasFactory; | ||
use Translatable; | ||
|
||
public array $translatable = [ | ||
'title', | ||
'badge' | ||
]; | ||
|
||
protected $casts = [ | ||
'title' => 'array', | ||
'badge' => 'array', | ||
'permissions' => 'array' | ||
]; | ||
|
||
/** | ||
* The table name | ||
* | ||
* @var string | ||
*/ | ||
protected $table = "menu_items"; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
"menu_id", | ||
"title", | ||
"group", | ||
"icon", | ||
"badge_color", | ||
"has_badge", | ||
"has_badge_query", | ||
"badge_table", | ||
"badge_condation", | ||
"badge", | ||
"is_route", | ||
"route", | ||
"url", | ||
"new_tab", | ||
"permissions", | ||
"order", | ||
]; | ||
|
||
|
||
public function menu() | ||
{ | ||
return $this->belongsTo(Menu::class, 'menu_id', 'id'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMenus\Resources\MenuResource\Pages; | ||
|
||
use Filament\Actions\CreateAction; | ||
use Filament\Resources\Pages\CreateRecord; | ||
use TomatoPHP\FilamentMenus\Resources\MenuResource; | ||
use Filament\Resources\Pages\ManageRecords; | ||
|
||
class CreateMenus extends CreateRecord | ||
{ | ||
protected static string $resource = MenuResource::class; | ||
|
||
#[Reactive] | ||
public ?string $local = "en"; | ||
public function setLocal($local){ | ||
$this->local = $local; | ||
$this->activeLocale = $local; | ||
} | ||
|
||
|
||
public function getTitle(): string | ||
{ | ||
return trans('filament-menus::messages.title'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace TomatoPHP\FilamentMenus\Resources\MenuResource\Pages; | ||
|
||
use Filament\Actions\CreateAction; | ||
use Filament\Resources\Pages\EditRecord; | ||
use TomatoPHP\FilamentMenus\Resources\MenuResource; | ||
use Filament\Resources\Pages\ManageRecords; | ||
|
||
class EditMenus extends EditRecord | ||
{ | ||
protected static string $resource = MenuResource::class; | ||
|
||
#[Reactive] | ||
public ?string $local = "en"; | ||
public function setLocal($local){ | ||
$this->local = $local; | ||
$this->activeLocale = $local; | ||
} | ||
|
||
|
||
public function getTitle(): string | ||
{ | ||
return trans('filament-menus::messages.title'); | ||
} | ||
} |
Oops, something went wrong.