PHP code example of codions / laravel-livewire-forms

1. Go to this page and download the library: Download codions/laravel-livewire-forms 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/ */

    

codions / laravel-livewire-forms example snippets


public function fields()
{
    return [
        Input::make('name', 'Name'),
        Input::make('email', 'Email')->type('email'),
        Input::make('password', 'Password')->type('password'),
    ];
}

public function buttons()
{
    return [
        Button::make('Create User')->click('createUser'),
        Button::make('Cancel', 'secondary')->url('/'),
    ];
}

public function rules()
{
    return [
        'name' => ['5', 'unique:users'],
        'password' => ['

public function createUser()
{
    $this->validate();

    User::create([
        'name' => $this->data('name'),
        'email' => $this->data('email'),
        'password' => Hash::make($this->data('password')),
    ]);

    return redirect('/');
}

class Login extends FormSliderComponent
{
    public $title = 'Login';
    public $layout = 'layouts.card';
    public $btnText = 'Login';
}

class UpdateUserForm extends FormComponent
{
    public $title = 'Update User';
    
    public function mount(User $user)
    {
        $this->data = $user->toArray();
    }
}

public function createUser()
{
    User::create([
        'name' => $this->data('name'),
        'email' => $this->data('email'),
        'likes_turtles' => $this->data('answers.likes_turtles'),
    ]);
}

Input::make('name', 'Name'), // defaults to defer
Input::make('name', 'Name')->instant(), // bind on keyup 
Input::make('name', 'Name')->defer(), // bind on action 
Input::make('name', 'Name')->lazy(), // bind on change
Input::make('name', 'Name')->debounce(500), // bind after 500ms delay 

Input::make('name', 'Name'), // defaults to normal sizing
Input::make('name', 'Name')->small(), // small sizing
Input::make('name', 'Name')->large(), // large sizing

Input::make('name', 'Name')->disabled(),
Input::make('name', 'Name')->readonly(),
Input::make('name', 'Name')->plaintext(),

Input::make('name', 'Name')->help('Please tell us your name!'),

Alert::make('It worked!'),
Alert::make('Something bad happened.', 'danger'),
Alert::make('Something else happened.')->dismissible(),

Arrayable::make('locations', 'Locations')->fields([
    Input::make('city')->placeholder('City'),
    Select::make('state')->placeholder('State')->options(['FL', 'TX']),
]),

Row::make()->fields([
    Input::make('city')->placeholder('City'),
    Select::make('state')->placeholder('State')->options(['FL', 'TX']),
]),

Button::make('Register')->click('register'),
Button::make('Already registered?', 'secondary')->route('login'),
Button::make('Go back home', 'link')->url('/'),

Checkbox::make('accept', 'I accept the terms'),
Checkbox::make('accept', 'I accept')->help('Please accept our terms'),
Checkbox::make('active', 'This user is active')->switch(),

Checkboxes::make('colors', 'Colors')->options(['Red', 'Green', 'Blue']),

Color::make('hair_color', 'Hair Color'),

Conditional::if($this->data('color') == 'green', [
    Input::make('green', 'Green'),
])->elseif($this->data('color') == 'blue', [
    Input::make('blue', 'Blue'),
])->else([
    Input::make('red', 'Red'),
]),

DynamicComponent::make('honey'),
DynamicComponent::make('honey', ['recaptcha' => true]),

File::make('avatar', 'Avatar'),
File::make('photos', 'Photos')->multiple(),
File::make('documents', 'Documents')->multiple()->disk('s3'),

Input::make('name', 'Name'),
Input::make('phone')->placeholder('Phone')->type('tel'),
Input::make('email', 'Email')->type('email')->large(),
Input::make('price', 'Price')->type('number')->append('$')->prepend('.00'),

Radio::make('gender', 'Gender')->options(['Male', 'Female']),

Select::make('color', 'Color')->options(['Red', 'Green', 'Blue']),
Select::make('color', 'Color')->options([
    '#ff0000' => 'Red',
    '#00ff00' => 'Green',
    '#0000ff' => 'Blue',
])->instant(),
Select::make('user_id', 'User')->options(User::pluck('name', 'id')->toArray()),

Input::Textarea('bio', 'Biography'),
Input::Textarea('bio', 'Biography')->rows(5),

View::make('custom-view', ['hello' => 'world']),

namespace App\Http\Livewire\Clients;

use Codions\LaravelLivewireForms\Components\Button;
use Codions\LaravelLivewireForms\Components\FormComponent;
use Codions\LaravelLivewireForms\Components\Input;
use Codions\LaravelLivewireForms\Components\Select;

class CreateClientForm extends FormComponent
{
    public $gridClass = 'row';

    public function fields()
    {
        return [
            Row::make()->fields([
                Input::make('name', 'Name')
                    ->placeholder('Full Name'),
                Input::make('email', 'Email')
                    ->type('email')
                    ->placeholder('Email, example: [email protected]'),
                Select::make('gender', 'Gender')
                    ->placeholder('Gender')
                    ->options(['Male', 'Female'])
                    ->addAttrs(['class' => 'd-block w-full']),
                Input::make('phone_no', 'Contact Number')
                    ->placeholder('(xxx) xxx xxxxx'),
                Input::make('street_address', 'Street Address'),
                Input::make('city', 'City'),
                Input::make('state', 'State / Parist'),
                Input::make('country', 'Country'),
            ])
        ];
    }

    public function buttons()
    {
        return [
            Button::make('Cancel', 'secondary')->url(route('team.index')),
            Button::make()->click('submit'),
        ];
    }
}