PHP code example of asosick / filament-layout-manager
1. Go to this page and download the library: Download asosick/filament-layout-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asosick / filament-layout-manager example snippets
use Asosick\FilamentLayoutManager\Pages\LayoutManagerPage;
class TestPage extends LayoutManagerPage {}
use Asosick\FilamentLayoutManager\Pages\LayoutManagerPage;
class TestPage extends LayoutManagerPage
{
// protected static string $view = 'filament.pages.custom-page'; <- DELETE OR COMMENT THIS
}
class TestPage extends LayoutManagerPage
{
protected function getComponents(): array
{
// Replace with your chosen components
return [
LivewireComponent::class,
CompaniesWidget::class,
BlogPostsChart::class,
];
}
}
protected function getGridColumns(): int
{
return 6; // Max of 12
}
class TestPage extends LayoutManagerPage
{
protected function getComponents(): array
{
return [
CompaniesWidget::make([
'company' => 'Apple'
]),
];
}
}
class CompaniesWidget extends BaseWidget
{
public array $data;
public function mount(array $data){
$this->data = $data;
}
//... other methods & properties
}
class TestPage extends LayoutManagerPage
{
protected function getComponents(): array
{
return [
CompaniesWidget::class, //Default select option is `CompaniesWidget`
];
}
protected function getComponentSelectOptions(): array
{
return ['My Company Widget'];
}
}
namespace App\Livewire;
use Asosick\FilamentLayoutManager\Http\Livewire\LayoutManager;
use Filament\Actions\Action;
class CustomLayoutManager extends LayoutManager
{
/* Example of changing the colour of the add button to red */
public function addAction(): Action
{
return parent::addAction()->color('danger');
}
}
// newly published config file
return [
'layout_manager' => \App\Livewire\CustomLayoutManager::class,
// Other settings
// ...
];
namespace App\Livewire;
use Asosick\FilamentLayoutManager\Http\Livewire\LayoutManager;
use Illuminate\Support\Arr;
class CustomLayoutManager extends LayoutManager
{
public function save(): void
{
$user = auth()->user();
$user->settings = [
'container' => $this->container
];
$user->save();
}
public function load(): void
{
$user = auth()->user();
$this->container = Arr::get(
json_decode($user->settings, true),
'container',
[]
);
}
}
namespace App\Livewire;
use Asosick\FilamentLayoutManager\Http\Livewire\LayoutManager;
use Filament\Actions\Action;
use Illuminate\Support\Facades\Log;
class CustomLayoutManager extends LayoutManager
{
public function getHeaderActions(): array
{
return [
Action::make('hello')
->action(fn () => Log::info('hello world!')),
Action::make('goodbye')
->action(fn () => Log::info('goodbye world!')),
];
}
}
namespace App\Filament\Pages;
use Asosick\FilamentLayoutManager\Pages\LayoutManagerPage;
use Filament\Actions\Action;
class TestPage extends LayoutManagerPage
{
/* Wrap the LayoutManager component in a traditional filament page */
public function shouldWrapInFilamentPage(): bool
{
return true;
}
/* Can now use existing filament header actions */
protected function getHeaderActions(): array
{
return [
Action::make('my-header-action')
];
}
}
/* In filament-layout-manage.php config file */
'wrap_in_filament_page' => true,
/*
Provide the following as part of your child component (like a widget class), to get the id and your data (in store).
*/
public string $container_key;
public array $store;
public function mount(string $container_key, array $store){
$this->container_key = $container_key;
$this->store = $store;
}