Skip to content

Commit

Permalink
Merge branch 'main' of github.com:aymanalhattami/filament-page-with-s…
Browse files Browse the repository at this point in the history
…idebar
  • Loading branch information
aymanalhattami committed Aug 30, 2023
2 parents bea732a + d513633 commit 0f6385b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RTL (Right to Left)
Please check out this video by Povilas Korop (Laravel Daily) to learn more about our package: [link](https://www.youtube.com/watch?v=J7dH8O-YBnY)

> **Note:**
> For Filament 2.x use version 1.x
> For [Filament 2.x](https://filamentphp.com/docs/2.x/admin/installation) use [version 1.x](https://github.com/aymanalhattami/filament-page-with-sidebar/tree/1.x)
## Installation
```bash
Expand Down Expand Up @@ -114,6 +114,31 @@ class UserResource extends Resource

```

or add the trait ```AymanAlhattami\FilamentPageWithSidebar\Traits\HasPageSidebar``` on any page you want the sidebar included.
This trait will add the sidebar to the Page. Add it to all your Resource Pages :

```php
// ...
use AymanAlhattami\FilamentPageWithSidebar\Traits\HasPageSidebar;

class ViewUser extends ViewRecord
{
use HasPageSidebar; // use this trait to activate the Sidebar

protected static string $resource = UserResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
```

If you wan to use custom view, you can still overwrite the default value with ```protected static string $hasSidebar = false;``` and ```protected static $view = 'filament.[...].user-resource.pages.view-user';```


## More Options

### Set title and description for sidebar
Expand Down
3 changes: 3 additions & 0 deletions resources/views/proxy.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<x-filament-page-with-sidebar::page>
@include($this->getIncludedSidebarView())
</x-filament-page-with-sidebar::page>
53 changes: 53 additions & 0 deletions src/Traits/HasPageSidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace AymanAlhattami\FilamentPageWithSidebar\Traits;

trait HasPageSidebar
{
/**
* Activate or not the automatic sidebar to the page
* If you change it to FALSE then add manually the $view
* parameter
* @var boolean
*/

public static bool $hasSidebar = true;

/**
* public function mountHasPageSidebar
*
* Register automatically view if available and activated
*/
public function bootHasPageSidebar(): void
{
// Why boot ? https://livewire.laravel.com/docs/lifecycle-hooks#boot

// Using ${'view'} instead of $view in order to avoid Intelephense warning
if (static::$hasSidebar) {
static::${'view'} = 'filament-page-with-sidebar::proxy';
}
}

/**
* public function getIncludedSidebarView
*
* Return the view that will be used in the sidebar proxy.
*
* @Return string \Filament\Pages\Page View to be included
*/
public function getIncludedSidebarView(): string
{
if (is_subclass_of($this, '\Filament\Pages\Page')) {
$props = collect(
(new \ReflectionClass($this))->getDefaultProperties()
);

if ($props->get('view')) {
return $props->get('view');
}
}

// Else:
throw new \Exception('No view detected for the Sidebar. Implement Filament\Pages\Page object with valid static $view');
}
}

0 comments on commit 0f6385b

Please sign in to comment.