Tailwire
It's like React for PHP. Powered by Laravel, Livewire, Tailwind, & Alpine.
Features:
- Use a custom view component class namespace
- Declare routes directly inside full page Livewire components
- Install Tailwind & Alpine with a single command
- Code using a component-based approach rather than MVC
- Write view code directly inside components (inline)
- Declare migrations & factory definitions inside models
Requirements:
- Laravel 8
- NPM
Installation
This package was designed to work with new Laravel projects.
Install Laravel via Composer/Docker/whatever you prefer:
laravel new my-app
Require Tailwire via Composer:
composer require heyjoe1984/tailwire
Install Tailwire:
php artisan tw:install
This will install and configure Tailwind & Alpine, create an app layout component, and a new User model.
When you're ready to start building your app, run npm run watch
to activate tailwind JIT mode.
Commands
Create a Livewire component with a route method and inline view included:
php artisan tw:livewire my-component-name
Create a view component in your custom namespace with an inline view included:
php artisan tw:view my-component-name
Create a model with migration & factory definition methods included:
php artisan tw:model my-model-name
Run model-based migrations:
php artisan tw:migrate {--fresh} {--seed}
Using Custom View Component Namespaces
Publish the package config:
php artisan vendor:publish
Update the view_namespace
to whatever you prefer:
'view_namespace' => 'App\\Http\\View',
Now any component created inside this namespace can be access via <x-my-component-name>
tags.
Declaring Full Page Livewire Routes
Create a route
method inside your Livewire component:
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class MyComponentName extends Component
{
public function route()
{
return Route::get('/my-component-name')
->name('my-component-name');
}
public function render()
{
return <<<'HTML'
<div>
<!-- Stop trying to control. -->
</div>
HTML;
}
}
The route
method should return the Laravel Route
facade.
Declaring Migrations & Factory Definitions Inside Models
Create migration
and definition
methods inside your model:
use Faker\Generator;
use Heyjoe1984\Tailwire\Traits\HasNewFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
class MyModelName extends Model
{
use HasNewFactory;
public function migration(Blueprint $table)
{
$table->id();
$table->string('name');
$table->timestamps();
}
public function definition(Generator $faker)
{
return [
'name' => $faker->name(),
];
}
}
Run the model-based migrations command:
php artisan tw:migrate
Use -f
for fresh migration, and -s
to seed using model-based factory definitions afterwards.
This command will also run your traditional migration files first for those edge-cases.