Skip to content

Instantly share code, notes, and snippets.

@Aslam97
Created October 10, 2022 11:19
Show Gist options
  • 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>
@Aslam97
Copy link
Author

Aslam97 commented Jul 3, 2024

@esperance-christ this code like 2 years ago. And what I see on X. That lunar move to Filament and since then, I dont use Lunar again. So I would suggest you ask directly to Lunar discord. They reply fast. Hopefully you solve your issue.

@esperance-christ
Copy link

Thanks you @Aslam97.

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