PHP code example of redbastie / tailwire
1. Go to this page and download the library: Download redbastie/tailwire library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redbastie / tailwire example snippets
class Login extends Component
{
public $routeUri = '/login';
public $routeName = 'login';
public $routeMiddleware = 'guest';
class Vehicle extends Component
{
public $routeUri = '/vehicle/{vehicle}';
public $routeName = 'vehicle';
public $routeMiddleware = ['auth'];
public $vehicle;
public function mount(Vehicle $vehicle)
{
$this->vehicle = $vehicle;
}
class Login extends Component
{
public $viewTitle = 'Login';
public $viewExtends = 'layouts.app';
class App extends Component
{
public function view(View $v)
{
return $v->body(
$v->header('Header content')->class('text-xl'),
$v->yield(),
$v->footer('Footer content')->class('text-sm'),
)->class('bg-gray-100');
class Home extends Component
{
public function view(View $v)
{
return $v->section(
$v->h1('Home')->class('text-xl px-6 py-4'),
$v->p('You are logged in!')->class('p-6')
)->class('bg-white shadow divide-y');
}
$v->img()->src(asset('images/icon-fav.png'))->class('w-5 h-5')
$v->div(
$v->p('Hello')->class('text-red-600'),
$v->p('World')->class('text-green-600'),
)->class('bg-blue-100')
$v->icon('refresh')->class('animate-spin text-gray-400 w-5 h-5 mx-auto')
$v->input()->type('email')->id('email')->wireModelDefer('email')
$email = $this->model('email');
$userName = $this->model('user.name');
$validated = $this->validate([
'email' => ['
$v->if($this->error('email'),
fn() => $v->p($this->error('email'))->class('text-xs text-red-600')
)
class Counter extends Component
{
public $count = 0;
public function view(View $v)
{
return $v->div(
$v->button('Increment Count')->wireClick('incrementCount'),
$v->p($this->count)->class('text-blue-600'),
);
}
function incrementCount()
{
$this->count++;
}
public function view(View $v)
{
return $v->div(
$v->button('Increment Count')->wireClick('incrementCount', 2),
$v->p($this->count)->class('text-blue-600'),
);
}
function incrementCount($amount)
{
$this->count += $amount;
}
$v->if(Auth::guest(),
fn() => $v->p('You are signed out.')
)->else(
fn() => $v->p('You are signed in!)
)
$v->each(Vehicle::all(),
fn(Vehicle $vehicle) => $v->div(
$v->p($vehicle->name),
$v->p($vehicle->created_at)->class('text-xs text-gray-600')
)
)->empty(
fn() => $v->p('No vehicles found.')
),
$v->
$v->icon('cog')->class('text-blue-600 w-5 h-5'),
$v->swipeDownRefresh(
$v->icon('refresh')->class('animate-spin text-gray-400 w-5 h-5 mx-auto')
)->class('mb-4'),
$v->infiniteScroll(
$v->icon('refresh')->class('animate-spin text-gray-400 w-5 h-5 mx-auto')
)->class('mt-4'),
$v->swipeDownRefresh(
$v->icon('refresh')->class('animate-spin text-gray-400 w-5 h-5 mx-auto')
)->class('mb-4'),
public function view(View $v)
{
return $v->section(
$v->h1('Vehicles')->class('text-xl mb-2'),
$v->each($this->query()->paginate($this->perPage),
fn(Vehicle $vehicle) => $v->div(
$v->p($vehicle->name),
$v->p(timezone($vehicle->created_at))->class('text-xs text-gray-600')
)->class('px-6 py-4')
),
$v->if($this->query()->count() > $this->perPage,
fn() => $v->infiniteScroll(
$v->icon('refresh')->class('animate-spin text-gray-400 w-5 h-5 mx-auto')
)->class('mt-4')
)
);
}
public function query()
{
return Vehicle::query()->orderBy('name');
}
$v->form(
$v->div(
$v->label('Email')->for('email'),
$v->input()->type('email')->id('email')->wireModelDefer('email')
->class(($this->error('email') ? 'border-red-500' : 'border-gray-300') . ' w-full'),
$v->if($this->error('email'), fn() => $v->p($this->error('email'))->class('text-xs text-red-600'))
)->class('space-y-1'),
$v->div(
$v->label('Password')->for('password'),
$v->input()->type('password')->id('password')->wireModelDefer('password')
->class(($this->error('password') ? 'border-red-500' : 'border-gray-300') . ' w-full'),
$v->if($this->error('password'), fn() => $v->p($this->error('password'))->class('text-xs text-red-600'))
)->class('space-y-1'),
$v->honey(), // stop spam bots!
$v->button('Register')->type('submit')->class('text-white bg-blue-600 w-full py-2')
)->wireSubmitPrevent('register')->class('space-y-4 p-6')
$v->honey(true) // use honey with recaptcha (be sure to configure it!)
console
php artisan tailwire:install
console
php artisan tailwire:install
console
php artisan tailwire:auth
console
php artisan tailwire:component VehicleItem
php artisan tailwire:component VehiclePage --full
php artisan tailwire:component Admin/InsuranceDialog --modal
php artisan tailwire:component VehicleList --list --model=Vehicle
console
php artisan tailwire:crud {class}
console
php artisan tailwire:crud Vehicle
php artisan tailwire:crud Admin/Insurance
console
php artisan tailwire:model {class}
console
php artisan tailwire:model Vehicle
php artisan tailwire:model Admin/Insurance
console
php artisan tailwire:migrate {--fresh} {--seed} {--force}