Skip to content

Instantly share code, notes, and snippets.

@Aslam97
Created October 10, 2022 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aslam97/4b6ce8b4abbc3527bea0e46ed4d3f88f to your computer and use it in GitHub Desktop.
Save Aslam97/4b6ce8b4abbc3527bea0e46ed4d3f88f to your computer and use it in GitHub Desktop.
Create Lunar Page and Component

This follow the lunar structure code.

First create folder call Pages and Components inside App\Http\Livewire it will become something like this.

App\Http\Livewire\Components App\Http\Livewire\Pages

Moving on. we will create new Page call Foo

  1. Create livewire component call FooIndex inside Pages
<?php

namespace App\Http\Livewire\Pages\Foo;

use Livewire\Component;

class FooIndex extends Component
{
    public function render()
    {
        // in this example iam using default lunar layout.
        // if you want to use your own layout it's up to you
        return view('livewire.pages.foo.index')
            ->layout('adminhub::layouts.app'); 
    }
}
  1. Create livewire view call index.blade.php in resources/views/livewire/pages/foo/index.blade.php
<div>
    This is from foo index
</div>
  1. Add foo routes

Note: Pages only for routes.

Route::group([], function () {
    Route::get('foo', \App\Http\Livewire\Pages\FooIndex::class)->name('hub.foo.index');
});
  1. Add custom menu inside AppServiceProvider. refrence https://docs.lunarphp.io/extending/admin-hub.html#adding-to-menus
$slot = Menu::slot('sidebar');

$slot->addItem(function ($item) {
    $item->name('Foo')->handle('hub.foo')
        ->route('hub.foo.index')
        ->icon('foo');
});

First create FooIndex inside Pages

App\Http\Livewire\Pages\FooIndex

<?php

namespace App\Http\Livewire\Pages\FooIndex;

use Livewire\Component;

class FooIndex extends Component
{
  public function render()
  {
    return view('livewire.pages.foo.index')
      ->layout('adminhub::layouts.app');
  }
}

Inside resources/views/livewire/pages/foo/index.blade.php

<div>
    @livewire('hub.components.settings.application.index')
</div>
@g-trema
Copy link

g-trema commented Mar 25, 2024

Warning: for this to work, the route must be defined as follows in the routes>web.php file :

  1. Declare use of "Authenticate" middleware
use Lunar\Hub\Http\Middleware\Authenticate;
  1. Using middleware for route declaration
Route::group([
    'middleware' => [
        Authenticate::class,
    ],
], function () {
    Route::get('foo', \App\Http\Livewire\Pages\FooIndex::class)->name('hub.foo.index');
});

[EDIT] but thank you for sharing, it helps me a LOT! 🥇 [/EDIT]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment