Giter VIP home page Giter VIP logo

laravel-livewire-discover's Introduction

laravel_livewire_discover.jpg

Laravel Livewire Discover

Packagist Downloads GitHub License GitHub Release

Automatically discover and load/register multiple/different class namespaces for Livewire components.

Installation

You can install the package via composer:

composer require joserick/laravel-livewire-discover

Enjoying this package? "Buy Me A Coffee"

Config

Add to AppServiceProvider.php

public function boot(): void
{
	// Load multiples namespace for Livewire components.
	Livewire::discover('Namespaces\\Livewire', 'my-components');
	Livewire::discover('User\\Repository\\Livewire', 'new-components');
	...
}

Or use the config: 'config/laravel-livewire-discover.php'

# Publish the config
php artisan vendor:publish --tag livewire-discover-config
// Load the namespace to Livewire components.
'class_namespaces' => [
	// 'prefix' => 'namespace\\package',
	'my-components' => 'Namespaces\\Livewire',
	'new-components' => 'User\\Repository\\Livewire',
],

Use

<!-- Call Livewire Components. -->
<livewire:my-components-devices /> <!-- Class: Namespace\Livewire\Devices; -->
<livewire:new-components-devices-table /> <!-- Class: User\Repository\Livewire\DevicesTable; -->

Or

// Load Livewire Component from Route
use Namespaces\Livewire\Devices;
use User\Repository\Livewire\DevicesTable;

Route::get('/devices', Devices::class); // resolve name my-components-devices
Route::get('/devices_table', DevicesTable::class); // resolve name new-components-devices-table

License

The GNU Public License (GPLv3). Please see License File for more information.

laravel-livewire-discover's People

Contributors

joserick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

laravel-livewire-discover's Issues

Volt?

Cool package! Any idea if it can work with Volt?

config

'class_namespaces' => [
         'tools' => 'App\\Tools',
    ],

App/Tools/test.blade.php

<?php

use Livewire\Volt\Component;

new class extends Component {


} ?>

<div>
    Hi!
</div>

Home page

On the home page, I'm calling <livewire:tools-test /> and getting Unable to find component: [test]

The package is definitely trying, because it would say [tools-test] if not.

Any idea what I missed?

Support for Full Page Component?

I'm using https://github.com/apiato/apiato framework and i can't make it work.

`<?php

return [

/*
|---------------------------------------------------------------------------
| Class Namespaces
|---------------------------------------------------------------------------
|
| This values sets the class namespace for Livewire component classes in
| your application. This is used to discover the Livewire components.
|
*/

'class_namespaces' => [
    // 'prefix' => '//namespace//',
    'root' => 'App\\Containers\\AppSection\\Authentication\\UI\\WEB\\Components',
],

];`

I have my component here
`<?php

namespace App\Containers\AppSection\Authentication\UI\WEB\Components;

use Livewire\Component;

class Counter extends Component
{
public $count = 1;

public function increment()
{
    $this->count++;
}

public function decrement()
{
    $this->count--;
}

public function render()
{
    return view('appSection@authentication::counter');
}

}`

and the app.layout, I just ran the command in livewire docs so its in /resources/views/components/views/layouts/app.blade.php
So, The component is rendering when i call the route

image

but when i hit buttons, display the image above.

any help?

Feature Request - Resolve Nested Namespaces

Hey,

I believe having the package resolve nested namespaces automatically would be a good feature.

For example:

So take a component in the namespace:

namespace ClockingSystems\Auth\Livewire\Pages;

Then in the config file we'll define this:

'class_namespaces' => [
        'clocking-systems.auth' => 'ClockingSystems\\Auth\\Livewire',
    ],

This will give this error when using a full page component:

Unable to find component: [clocking-systems.auth-login]

Changing the namespace to include the pages namespace will allow it to work:

'class_namespaces' => [
        'clocking-systems.auth' => 'ClockingSystems\\Auth\\Livewire\\Pages',
    ],

I believe it should work like this

'class_namespaces' => [
        'clocking-systems.auth' => 'ClockingSystems\\Auth\\Livewire',
    ],

Which allows use of components in nested namespaces such as

<livewire:clocking-systems.auth.pages.login/>
<livewire:clocking-systems.auth.modals.forgot-password/>

This is how the livewire component discovery works by default

Can't render a livewire inside view().

File: laravel-livewire-discover.php

'class_namespaces' => [
    'auth' => 'App\\Containers\\AppSection\\Authentication\\UI\\WEB\\Components',
    'ship' => 'App\\Ship\\Components',
]

Somewhere in X component (using filament table)

....
->actions([
    Action::make('detalle')
        ->label('Ver')
        ->modalHeading('Capacitaciones del establecimiento')
        ->modalContent(
            fn(Establecimiento $record): View => view(
                'livewire::ship-sidebar',
            )
        )
        ->modalSubmitAction(false)
        ->modalCancelAction(false)
        ->modalWidth(MaxWidth::FiveExtraLarge),
])
....

I'm using sidebar just for testing purpose, of course.
image

But in my app layout. Works!
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.