Crud operation in laravel 9 step by step; Through this tutorial, we will learn step by step how to make simple crud operation app in laravel 9. And how to validate add & update form data on server-side in laravel 9 crud app.
This laravel 9 crud operation step by step tutorial will create a simple company crud operation app in laravel 9 app with validation. Using crud operation in laravel 9 app, you can learn how to insert, read, update and delete data from database in laravel 9.
Laravel 9 CRUD Example | Laravel 9 Beginners CRUD Tutorial
Use the following steps to create crud operation app in laravel 9; as follows:
- Step 1 – Download Laravel 9 App
- Step 2 – Setup Database with App
- Step 3 – Create Company Model & Migration For CRUD App
- Step 4 – Create Routes
- Step 5 – Create Company CRUD Controller By Artisan Command
- Step 6 – Create Blade Views File
- Make Directory Name Companies
- index.blade.php
- create.blade.php
- edit.blade.php
- Step 7 – Run Laravel CRUD App on Development Server
Step 1 – Download Laravel 9 App
First of all, download or install laravel 9 new setup. So, open the terminal and type the following command to install the new laravel 9 app into your machine:
composer create-project --prefer-dist laravel/laravel LaravelCRUD
Step 2 – Setup Database with App
Setup database with your downloaded/installed laravel app. So, you need to find .env file and setup database details as following:Crud operation in laravel 9 step by step; Through this tutorial, we will learn step by step how to make simple crud operation app in laravel 9. And how to validate add & update form data on server-side in laravel 9 crud app.
This laravel 9 crud operation step by step tutorial will create a simple company crud operation app in laravel 9 app with validation. Using crud operation in laravel 9 app, you can learn how to insert, read, update and delete data from database in laravel 9.
Laravel 9 CRUD Example | Laravel 9 Beginners CRUD Tutorial
Use the following steps to create crud operation app in laravel 9; as follows:
- Step 1 – Download Laravel 9 App
- Step 2 – Setup Database with App
- Step 3 – Create Company Model & Migration For CRUD App
- Step 4 – Create Routes
- Step 5 – Create Company CRUD Controller By Artisan Command
- Step 6 – Create Blade Views File
- Make Directory Name Companies
- index.blade.php
- create.blade.php
- edit.blade.php
- Step 7 – Run Laravel CRUD App on Development Server
Step 1 – Download Laravel 9 App
First of all, download or install laravel 9 new setup. So, open the terminal and type the following command to install the new laravel 9 app into your machine:
composer create-project --prefer-dist laravel/laravel LaravelCRUD
Step 2 – Setup Database with App
Setup database with your downloaded/installed laravel app. So, you need to find .env file and setup database details as following:
1 2 3 4 5 6 | DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database-name DB_USERNAME=database-user-name DB_PASSWORD=database-password
|
edit.blade.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <! DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Edit Company Form - Laravel 9 CRUD Tutorial</ title > < link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" > </ head > < body > < div class = "container mt-2" > < div class = "row" > < div class = "col-lg-12 margin-tb" > < div class = "pull-left" > < h2 >Edit Company</ h2 > </ div > < div class = "pull-right" > < a class = "btn btn-primary" href = "{{ route('companies.index') }}" enctype = "multipart/form-data" > Back</ a > </ div > </ div > </ div > @if(session('status')) < div class = "alert alert-success mb-1 mt-1" > {{ session('status') }} </ div > @endif < form action="{{ route('companies.update',$company->id) }}" method="POST" enctype="multipart/form-data"> @csrf @method('PUT') < div class = "row" > < div class = "col-xs-12 col-sm-12 col-md-12" > < div class = "form-group" > < strong >Company Name:</ strong > < input type = "text" name = "name" value="{{ $company->name }}" class="form-control" placeholder="Company name"> @error('name') < div class = "alert alert-danger mt-1 mb-1" >{{ $message }}</ div > @enderror </ div > </ div > < div class = "col-xs-12 col-sm-12 col-md-12" > < div class = "form-group" > < strong >Company Email:</ strong > < input type = "email" name = "email" class = "form-control" placeholder = "Company Email" value="{{ $company->email }}"> @error('email') < div class = "alert alert-danger mt-1 mb-1" >{{ $message }}</ div > @enderror </ div > </ div > < div class = "col-xs-12 col-sm-12 col-md-12" > < div class = "form-group" > < strong >Company Address:</ strong > < input type = "text" name = "address" value="{{ $company->address }}" class="form-control" placeholder="Company Address"> @error('address') < div class = "alert alert-danger mt-1 mb-1" >{{ $message }}</ div > @enderror </ div > </ div > < button type = "submit" class = "btn btn-primary ml-3" >Submit</ button > </ div > </ form > </ div > </ body > </ html > |
If you submit the add or edit form blank. So the error message will be displayed with the help of the code given below:
1 2 3 | @error('name') < div class = "alert alert-danger mt-1 mb-1" >{{ $message }}</ div > @enderror |
Step 7 – Run Development Server
Last step, open command prompt and run the following command to start developement server:
php artisan serve
Then open your browser and hit the following url on it:
http://127.0.0.1:8000/companies
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
หมายเหตุ: มีเพียงสมาชิกของบล็อกนี้เท่านั้นที่สามารถแสดงความคิดเห็น