Nuevo Documento de Microsoft Word
Nuevo Documento de Microsoft Word
Nuevo Documento de Microsoft Word
Powered By
Pause
Unmute
Loaded: 4.02%
Fullscreen
Now, let's see article of laravel 8 livewire crud example. This tutorial will give you
simple example of laravel 8 livewire crud with jetstream & tailwind css. i would like to
show you laravel 8 livewire crud with modal. We will look at example of laravel 8
jetstream livewire crud application example.
In this example i will show you step by step laravel 8 livewire crud app with
modal tailwind css.
Laravel 8 jetstream designed by Tailwind CSS and they provide auth using
livewire and Inertia. i will show you how to create module with livewire on
default jetstream auth in laravel 8.
Here, bellow i written step by step, so you can easily start simple post master
with your existing step up of laravel 8 jetstream auth with tailwind css. you
just need to follow few bellow step and you will get layout as like bellow:
Preview:
List View:
Create View:
Update View:
Step 1: Install Laravel 8
now, we need to create authentication using bellow command. you can create
basic login, register and email verification. if you want to create team
management then you have to pass addition parameter. you can see bellow
commands:
npm install
Here, we need create database migration for files table and also we will create
model for files table.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* @return void
*/
$table->id();
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
/**
* @return void
*/
Schema::dropIfExists('posts');
App/Models/Post.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\
HasFactory;
use Illuminate\Database\Eloquent\Model;
use HasFactory;
/**
* @var array
*/
protected $fillable = [
'title', 'body'
];
}
Read Also: Laravel 8 CRUD Application Tutorial for Beginners
Now here we will create livewire component using their command. so run
bellow command to create post crud application component.
app/Http/Livewire/Posts.php
resources/views/livewire/posts.blade.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Post;
public $isOpen = 0;
/**
* @var array
*/
$this->posts = Post::all();
return view('livewire.posts');
}
/**
* @var array
*/
$this->resetInputFields();
$this->openModal();
/**
* @var array
*/
$this->isOpen = true;
/**
*
* @var array
*/
$this->isOpen = false;
/**
* @var array
*/
$this->title = '';
$this->body = '';
$this->post_id = '';
/**
* @var array
*/
$this->validate([
]);
]);
session()->flash('message',
$this->closeModal();
$this->resetInputFields();
/**
* @var array
*/
$post = Post::findOrFail($id);
$this->post_id = $id;
$this->title = $post->title;
$this->body = $post->body;
$this->openModal();
/**
* @var array
*/
Post::find($id)->delete();
Here, we will update following list of files for our listing page, create page.
<x-slot name="header">
</h2>
</x-slot>
<div class="py-12">
@if (session()->has('message'))
<div class="flex">
<div>
<p class="text-
sm">{{ session('message') }}</p>
</div>
</div>
</div>
@endif
@include('livewire.create')
@endif
<thead>
<tr class="bg-gray-100">
</tr>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<button
wire:click="delete({{ $post->id }})" class="bg-red-
500 hover:bg-red-700 text-white font-bold py-2 px-4
rounded">Delete</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
resources/views/livewire/create.blade.php
</div>
<!-- This element is to trick the browser into
centering the modal contents. -->
<form>
<div class="">
<div class="mb-4">
<label
for="exampleFormControlInput1" class="block text-
gray-700 text-sm font-bold mb-2">Title:</label>
</div>
<div class="mb-4">
<label
for="exampleFormControlInput2" class="block text-
gray-700 text-sm font-bold mb-2">Body:</label>
<textarea class="shadow
appearance-none border rounded w-full py-2 px-3
text-gray-700 leading-tight focus:outline-none
focus:shadow-outline" id="exampleFormControlInput2"
wire:model="body" placeholder="Enter
Body"></textarea>
</div>
</div>
</div>
<button wire:click.prevent="store()"
type="button" class="inline-flex justify-center w-
full rounded-md border border-transparent px-4 py-2
bg-green-600 text-base leading-6 font-medium text-
white shadow-sm hover:bg-green-500 focus:outline-
none focus:border-green-700 focus:shadow-outline-
green transition ease-in-out duration-150 sm:text-sm
sm:leading-5">
Save
</button>
</span>
<button wire:click="closeModal()"
type="button" class="inline-flex justify-center w-
full rounded-md border border-gray-300 px-4 py-2 bg-
white text-base leading-6 font-medium text-gray-700
shadow-sm hover:text-gray-500 focus:outline-none
focus:border-blue-300 focus:shadow-outline-blue
transition ease-in-out duration-150 sm:text-sm
sm:leading-5">
Cancel
</button>
</span>
</form>
</div>
</div>
</div>
</div>
In third step, we will create routes for multiple file upload. so create two route
with GET and POST route example.
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Posts;
/*
|---------------------------------------------------
-----------------------
| Web Routes
|---------------------------------------------------
-----------------------
*/
Route::get('post', Posts::class);
now you can run app and login as user, then you can open bellow url:
Read Also: Laravel 8 Send Mail using Gmail SMTP Server
//localhost:8000/post