PHP code example of livewire / blaze
1. Go to this page and download the library: Download livewire/blaze 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/ */
livewire / blaze example snippets
use Livewire\Blaze\Blaze;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Blaze::optimize()->in(resource_path('views/components'));
// ...
}
Blaze::optimize()
->in(resource_path('views/components/button'))
->in(resource_path('views/components/modal'));
Blaze::optimize()
->in(resource_path('views/components'))
->in(resource_path('views/components/legacy'), compile: false);
Blaze::optimize()
->in(resource_path('views/components/icons'), memo: true)
->in(resource_path('views/components/cards'), fold: true);
function _c4f8e2a1($__data, $__slots) {
$type = $__data['type'] ?? 'button';
$attributes = new BlazeAttributeBag($__data);
// ...
}
_c4f8e2a1(['type' => 'submit'], ['default' => 'Send']);
use Livewire\Blaze\Blaze;
public function boot(): void
{
Blaze::debug();
// ...
}
Blaze::optimize()
->in(resource_path('views/components'))
->in(resource_path('views/components/ui'), fold: true)
->in(resource_path('views/components/icons'), memo: true)
->in(resource_path('views/components/legacy'), compile: false);
Blaze::enable(); // Enable Blaze compilation
Blaze::debug(); // Enable debug mode
Blaze::throw(); // Throw exceptions encountered during folding
bash
php artisan view:clear
blade
<x-icon :name="$task->status->icon" />
blade
$key = Memo::key('icon', ['name' => $task->status->icon]); blade
@blaze(fold: true)
@props(['color'])
@php
$classes = match($color) {
'red' => 'bg-red-500 hover:bg-red-400',
'blue' => 'bg-blue-500 hover:bg-blue-400',
default => 'bg-gray-500 hover:bg-gray-400',
};
@endphp
<button {{ $attributes->class($classes) }}>
{{ $slot }}
</button>
blade
<x-button :color="$deleting ? 'red' : 'blue'" />
blade
<x-button color="ATTR_PLACEHOLDER_1">
blade
@php
$classes = match("ATTR_PLACEHOLDER_1") {
'red' => 'bg-red-500 hover:bg-red-400',
'blue' => 'bg-blue-500 hover:bg-blue-400',
default => 'bg-gray-500 hover:bg-gray-400',
};
@endphp
blade
@blaze(fold: true, unsafe: ['href'])
@php
$active = $attributes->get('href') === url()->current();
@endphp
<a {{ $attributes->merge(['data-active' => $active]) }}>
{{ $slot }}
</a>
blade
@blaze(fold: true, unsafe: ['attributes'])
@php
$active = $attributes->get('href') === url()->current();
$external = $attributes->get('target') === '_blank';
@endphp
<a {{ $attributes->merge(['data-active' => $active]) }}>
@if($external)
...
@endif
</a>
bash
php artisan view:clear