By Hardik Savani November 28, 2020 Category : LaravelPauseUnmuteLoaded: 2.69%FullscreenHi Dev,
This simple article demonstrates of laravel livewire wizard form. you can see laravel livewire multi step form example. step by step explain wizard form bootstrap laravel livewire. i would like to share with you step by step wizard form in laravel livewire. Let's get started with livewire multi step form laravel example.
we can easily create multi step form using livewire in laravel 6, laravel 7, laravel 8 and laravel 9 version. let's see simple example of laravel livewire wizard form.
Livewire is a full-stack framework for Laravel framework that makes building dynamic interfaces simple, without leaving the comfort of Laravel. if you are using livewire with laravel then you don't worry about writing jquery ajax code, livewire will help to write very simple way jquery ajax code using php. without page refresh laravel validation will works, form will submit etc.
Here, i will give you very simple example to multi step using bootstrap wizard design. we will create product table and create new record with multi step.
So, let's follow bellow step and you will get bellow layout:
Step 1 : Install Laravel 8
first of all we need to get fresh Laravel 8 version application using bellow command, So open your terminal OR command prompt and run bellow command:
composer create-project --prefer-dist laravel/laravel blog
Step 2 : Create Migration and Model
Here, we need create database migration for files table and also we will create model for files table.
php artisan make:migration create_products_table
Migration:
<?php use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema; class CreateProductcTable extends Migration{ /** * Run the migrations. * * @return void */ public function up() { Schema::create('products', function (Blueprint $table) { $table->id(); $table->string('name')->nullable(); $table->longText('description')->nullable(); $table->float('amount')->nullable(); $table->boolean('status')->default(0); $table->integer('stock')->default(0); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('products'); }}
php artisan migrate
now we will create Product model by using following command:
php artisan make:model Product
App/Models/Product.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model; class Product extends Model{ use HasFactory; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'amount', 'description', 'status', 'stock' ];}
now we will create one route for calling our example, so let's add new route to web.php file as bellow:
routes/web.php
Route::get('wizard', function () { return view('default');});
Step 6: Create View File
here, we will create blade file for call form route. in this file we will use @livewireStyles, @livewireScripts and @livewire('wizard'). so let's add it.