Refactor registering directives and components.

This commit is contained in:
Ryan Scherler
2020-04-15 12:31:08 -07:00
parent f612f00d78
commit 93d36bd508
3 changed files with 37 additions and 7 deletions
@@ -4,14 +4,14 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateGlobalsTable extends Migration
class CreateGlobalSetsTable extends Migration
{
/**
* The name of the table for the migration.
*
* @var string
*/
protected $tableName = 'globals';
protected $tableName = 'global_sets';
/**
* Run the migrations.
+7 -5
View File
@@ -35,6 +35,7 @@ class FilamentServiceProvider extends ServiceProvider
$this->registerSingeltons();
$this->registerConfig();
$this->registerBindings();
$this->registerBlade();
}
/**
@@ -52,7 +53,6 @@ class FilamentServiceProvider extends ServiceProvider
$this->registerRoutes();
$this->registerMigrations();
$this->registerPublishing();
$this->registerBlade();
$this->registerLivewire();
$this->registerResources();
$this->registerTranslations();
@@ -255,16 +255,18 @@ class FilamentServiceProvider extends ServiceProvider
*/
public function registerBlade()
{
// Register package directives
// Register directives
Blade::directive('filamentAssets', [BladeDirectives::class, 'assets']);
Blade::directive('pushonce', [BladeDirectives::class, 'pushOnce']);
Blade::directive('endpushonce', [BladeDirectives::class, 'endPushOnce']);
// Automatically register package components
// Register components
$components = [];
foreach (File::glob(__DIR__.'/Http/Components/*.php') as $path) {
$baseName = basename($path, '.php');
Blade::component("\\Filament\\Http\\Components\\{$baseName}", 'filament-'.Str::of($baseName)->kebab());
$baseName= basename($path, '.php');
$components[] = "\\Filament\\Http\\Components\\{$baseName}";
}
$this->loadViewComponentsAs('filament', $components);
}
/**
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Filament\Models;
use Illuminate\Database\Eloquent\Model;
use Filament\Traits\FillsColumns;
class GlobalSet extends Model
{
use FillsColumns;
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'fields' => 'array',
];
public static function search($query)
{
return empty($query) ? static::query()
: static::where('id', $query)
->orWhere('name', 'like', '%'.$query.'%')
->orWhere('fields', 'like', '%'.$query.'%');
}
}