Skip to content

Commit

Permalink
Adapt to Livewire 3 folder structure (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sertxudev authored Mar 11, 2024
1 parent c28e99c commit 6311af0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ typing.

You will no longer need to download all the data at the startup, just get the data you're looking for.

## Requirements

**This package requires AlpineJS to work properly.**

If you're not going to use AlpineJS, you might want to publish the component view in order to replace the AlpineJS functionality.

```bash
php artisan vendor:publish --provider="SertxuDeveloper\Livewire\LivewireComboboxServiceProvider"
```

## Installation

You can install the package via composer:
Expand All @@ -43,14 +33,14 @@ First, you need to execute the following command in your terminal:
php artisan combobox:make UsersCombobox -m User
```

This will create a new component in the `App/Http/Livewire` directory.
This will create a new component in the `app/Livewire` directory.

The new `UsersCombobox` component will look like this:

```php
<?php

namespace App\Http\Livewire;
namespace App\Livewire;

use App\Models\User;
use SertxuDeveloper\LivewireCombobox\Components\Combobox;
Expand Down Expand Up @@ -95,7 +85,7 @@ You can also pass some parameters to the component:
<livewire:users-combobox name="author" label="Author" placeholder="Select a user">
```

> **Warning**<br>
> [!WARNING]
> If you don't pass any parameters, the component will use the default values.<br>
> It's recommended to pass the parameters to the component.<br>
> You can also add the values overriding the default values in the class.
Expand All @@ -111,7 +101,7 @@ The name of the events depends on the component name, this allows you to have mo

These events will be fired up, so the parent component can react to the user interaction.

> **Note**<br>
> [!Note]
> The `selected` event contains the selected model as a parameter.
## Adding filters
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ComboboxMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function buildClass($name): string {
* @param string $rootNamespace
*/
protected function getDefaultNamespace($rootNamespace): string {
return $rootNamespace.'\Http\Livewire';
return $rootNamespace.'\Livewire';
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/Console/ComboboxMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function test_command_can_be_executed(): void {
'name' => 'TestCombobox',
]);

$this->assertFileExists(app_path('Http/Livewire/TestCombobox.php'));
unlink(app_path('Http/Livewire/TestCombobox.php'));
$this->assertFileExists(app_path('Livewire/TestCombobox.php'));
unlink(app_path('Livewire/TestCombobox.php'));
}

/**
Expand All @@ -28,8 +28,8 @@ public function test_command_can_be_executed_with_model_option(): void {
'--model' => 'User',
]);

$this->assertFileExists(app_path('Http/Livewire/TestModelCombobox.php'));
unlink(app_path('Http/Livewire/TestModelCombobox.php'));
$this->assertFileExists(app_path('Livewire/TestModelCombobox.php'));
unlink(app_path('Livewire/TestModelCombobox.php'));
}

/**
Expand All @@ -41,12 +41,12 @@ public function test_command_generates_correct_file(): void {
'--model' => 'User',
]);

$contents = file_get_contents(app_path('Http/Livewire/TestModelCombobox.php'));
$contents = file_get_contents(app_path('Livewire/TestModelCombobox.php'));

$this->assertStringContainsString('class TestModelCombobox extends Combobox', $contents);
$this->assertStringContainsString('use App\Models\User;', $contents);

unlink(app_path('Http/Livewire/TestModelCombobox.php'));
unlink(app_path('Livewire/TestModelCombobox.php'));
}

/**
Expand All @@ -60,6 +60,6 @@ public function test_command_cannot_be_executed_with_invalid_model(): void {
'--model' => 'User-*Invalid\\Model',
]);

$this->assertFileDoesNotExist(app_path('Http/Livewire/TestModelCombobox.php'));
$this->assertFileDoesNotExist(app_path('Livewire/TestModelCombobox.php'));
}
}

0 comments on commit 6311af0

Please sign in to comment.