-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:aymanalhattami/filament-page-with-s…
…idebar
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
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
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> |
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,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'); | ||
} | ||
} |