1. Go to this page and download the library: Download bastinald/malzahar 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/ */
bastinald / malzahar example snippets
namespace App\Components\Blade\Forms;
use Bastinald\Malzahar\Components\Blade;
use Bastinald\Malzahar\Components\Html;
class Button extends Blade
{
public $color = 'blue';
public function attributes()
{
return [
'type' => 'button',
];
}
public function classes()
{
return [
'text-white rounded-md shadow-sm px-4 py-2',
'bg-' . $color . '-600 hover:bg-' . $color . '-700',
];
}
public function template()
{
return Html::button($this->slot)
->merge($this);
}
}
class Login extends Livewire
{
public $email;
public function template()
{
return GuestLayout::make(
Html::form(
Input::make()
->type('email')
->placeholder(__('Email'))
->error($this->error('email'))
->wireModelDefer('email'),
Button::make(__('Login'))
->color('red')
->type('submit')
->class('w-full'),
)->wireSubmitPrevent('login'),
);
}
class Home extends Livewire
{
public function route()
{
return Route::get('/home', static::class)
->name('home')
->middleware('auth');
}
public function title()
{
return __('Home');
}
public function template()
{
return AuthLayout::make(
Html::h1($this->title())
->class('text-3xl font-bold mb-4'),
Html::p(__('You are logged in!')),
);
}
}
class Alert extends Livewire
{
public $message;
public function mount($message)
{
$this->message = $message;
}
public function template()
{
return Html::div(
Html::p(__($this->message))
->class('font-bold mb-4'),
Html::button(__('Change Message'))
->class('bg-blue-600 text-white px-4 py-2')
->wireClick('changeMessage'),
);
}
public function changeMessage()
{
$this->message = 'I am a changed message.';
}
}
class Home extends Livewire
{
public function template()
{
return AuthLayout::make(
Html::h1($this->title())
->class('text-3xl font-bold mb-4'),
Alert::make()->message('Hello, world!'),
);
}
use App\Components\Blade\Forms\Button;
use App\Components\Blade\Forms\Input;
use App\Components\Blade\Layouts\GuestLayout;
use Bastinald\Malzahar\Components\Html;
use Bastinald\Malzahar\Components\Livewire;
class Login extends Livewire
{
public $email, $password;
public function template()
{
return GuestLayout::make(
Html::form(
Input::make()
->type('email')
->placeholder(__('Email'))
->error($this->error('email'))
->wireModelDefer('email'),
Input::make()
->type('password')
->placeholder(__('Password'))
->error($this->error('password'))
->wireModelDefer('password'),
Button::make(__('Login'))
->type('submit')
->class('w-full'),
)->wireSubmitPrevent('login'),
);
}
public function rules()
{
return [
'email' => ['
public $email;
public function template()
{
return Html::div(
Html::h1(__('Hello, world')),
Html::input()
->type('email')
->placeholder(__('Email'))
->wireModelDefer('email'),
Html::p(__('Look ma, no hands!'))
->class('text-blue-600 font-bold'),
);
}
public $color = 'blue';
public function template()
{
return Statement::if($this->color == 'red',
fn() => Html::h1(__('The color is red!'))
->class('text-red-600'),
)->elseif($this->color == 'blue',
fn() => Html::h2(__('The color is blue!'))
->class('text-blue-600'),
)->else(
fn() => Html::h3(__('The color is something else!')),
);
}