mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
REfine model resources - use trait rather than contract
This commit is contained in:
+2
-1
@@ -84,6 +84,7 @@ return [
|
||||
'active' => 'filament.dashboard', // string or named route (may also be an array @link https://github.com/dwightwatson/active)
|
||||
'label' => 'Dashboard',
|
||||
'icon' => 'heroicon-o-home', // optional icon name (Blade UI Kit @link https://github.com/blade-ui-kit/blade-heroicons)
|
||||
'sort' => -1, // sort order used by the navigation
|
||||
],
|
||||
|
||||
],
|
||||
@@ -99,7 +100,7 @@ return [
|
||||
*/
|
||||
|
||||
'components' => [
|
||||
// 'alert' => Components\Alerts\Alert::class,
|
||||
'nav' => Filament\View\Components\Nav::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
@inject('nav', 'Filament\Navigation')
|
||||
|
||||
<nav aria-label="primary" class="flex-grow px-4">
|
||||
<ol>
|
||||
@foreach($nav::all() as $item)
|
||||
@foreach($nav as $item)
|
||||
<li>
|
||||
<x-filament::nav-link
|
||||
:path="$item->path"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<x-filament::app-icon class="w-10 h-10 fill-current" />
|
||||
<span class="text-sm leading-tight font-semibold">{{ config('app.name') }}</span>
|
||||
</a>
|
||||
<x-filament::nav />
|
||||
<x-filament-nav />
|
||||
<x-filament::dropdown class="w-full text-left flex-grow flex items-center p-4 space-x-3 text-gray-600 transition-colors duration-200 hover:text-white hover:bg-gray-800" id="dropdown-user">
|
||||
<img src="{{ Auth::user()->avatar(32) }}" alt="{{ Auth::user()->name }}" srcset="{{ Auth::user()->avatar(32) }} 1x, {{ Auth::user()->avatar(64) }} 2x" class="flex-shrink-0 w-8 h-8 rounded" />
|
||||
<span class="flex-grow text-sm leading-tight font-semibold">{{ Auth::user()->name }}</span>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Contracts;
|
||||
|
||||
interface FilamentResource {
|
||||
public function actions(): array;
|
||||
}
|
||||
+4
-3
@@ -12,7 +12,7 @@ use Illuminate\Support\{
|
||||
Collection,
|
||||
HtmlString,
|
||||
};
|
||||
use Filament\Contracts\FilamentResource;
|
||||
use Filament\Traits\FilamentResource;
|
||||
|
||||
class Filament
|
||||
{
|
||||
@@ -144,7 +144,8 @@ class Filament
|
||||
|
||||
public function getResourceModels(): Collection
|
||||
{
|
||||
$models = collect(File::allFiles(app_path()))
|
||||
$app_path = config('filament.paths.models', app_path());
|
||||
$models = collect(File::allFiles($app_path))
|
||||
->map(function ($item) {
|
||||
$path = $item->getRelativePathName();
|
||||
$class = sprintf('\%s%s',
|
||||
@@ -160,7 +161,7 @@ class Filament
|
||||
|
||||
$reflection = new \ReflectionClass($class);
|
||||
return $reflection->isSubclassOf(Model::class) &&
|
||||
in_array(FilamentResource::class, class_implements($class)) &&
|
||||
in_array(FilamentResource::class, class_uses_recursive($class)) &&
|
||||
!$reflection->isAbstract();
|
||||
})->mapWithKeys(function ($class) {
|
||||
return [class_basename($class) => $class];
|
||||
|
||||
@@ -131,6 +131,7 @@ class FilamentServiceProvider extends ServiceProvider
|
||||
'active' => $route.'*',
|
||||
'label' => $model->label ?? Str::plural($key),
|
||||
'icon' => $model->icon ?? 'heroicon-o-database',
|
||||
'sort' => $model->sort ?? 0,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Traits;
|
||||
|
||||
trait FilamentResource
|
||||
{
|
||||
public function actions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Nav extends Component
|
||||
{
|
||||
public $nav;
|
||||
|
||||
/**
|
||||
* Create the component instance.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->nav = app('Filament\Navigation')
|
||||
->orderBy('sort', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\View\View|\Closure|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('filament::components.nav');
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ abstract class TestCase extends OrchestraTestCase
|
||||
'prefix' => '',
|
||||
]);
|
||||
|
||||
$app['config']->set('filament.paths.models', __DIR__.'/Database/Models');
|
||||
$app['config']->set('auth.providers.users.model', User::class);
|
||||
$app['config']->set('filament.models.user', User::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user