Laravel is world famous Number one php framework.it has various features.Laravel is a MVC architecture. In this tutorial will see how to make a crud application in Laravel 10.Laravel 10 – CRUD application tutorial with Example. Here is the Best Place to Learn Laravel 10 Articles.
Before get Start Course we need these requirements inorder to install Laravel 10.
- php version must be atleast 8.1
- composer version must be latest one
Lets do the Crud Step by Step Laravel 10 From Scratch
First Step
create a folder for your laravel project after create folder double click and go inside the folder.on the address bar of
the folder type cmd to get the command prompt.
Install Laravel 10
then type by following command to create the laravel project.
1 | composer create-project laravel/laravel studentcrud-app |
i attached the screen shot window below as you can see.
After Type the Command you have to wait until the project installation finish.
Database setup
Create the Database on xampp which name is dbschool
After created the database.
Change .env File
Change .env File for username, password and DB Name
After that run check the application the welcome screen of Laravel framework look like this.
1 | php artisan serve |
Create Migration
Create the tables
1 | php artisan make:migration create_students_table |
After that you can check the inside database folder migrations create_students_table.php
Click and open the Student table.
1 2 3 4 5 6 7 8 9 10 11 12 | public function up() { Schema::create('students', function (Blueprint $table) { $table->id(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('students'); } |
then create the following fields
$table->string(‘name’);
$table->string(‘address’);
$table->string(‘mobile’);
inside the function up() function i shown in below clearly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { public function up(): void { Schema::create('students', function (Blueprint $table) { $table->id(); $table->string("name"); $table->string("address"); $table->string("mobile"); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('students'); } }; |
After add the lines type. then type the command to create the tables
1 | php artisan migrate |
then table has been migrated
Create Controller
Create the controller name which is StudentController
1 | php artisan make:controller StudentController --resource |
Controller
After that Pass All view pages through Controller. you have to add the Model namespace here
use App\Models\Student; Data is coming from the database via Model.
View
we using view function so we need to use the use Illuminate\View\View;
Student Controller
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 | <?php namespace App\Http\Controllers; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Models\Student; use Illuminate\View\View; class StudentController extends Controller { public function index(): View { $students = Student::all(); return view ('students.index')->with('students', $students); } public function create(): View { return view('students.create'); } public function store(Request $request): RedirectResponse { $input = $request->all(); Student::create($input); return redirect('student')->with('flash_message', 'Student Addedd!'); } public function show(string $id): View { $student = Student::find($id); return view('students.show')->with('students', $student); } public function edit(string $id): View { $student = Student::find($id); return view('students.edit')->with('students', $student); } public function update(Request $request, string $id): RedirectResponse { $student = Student::find($id); $input = $request->all(); $student->update($input); return redirect('student')->with('flash_message', 'student Updated!'); } public function destroy(string $id): RedirectResponse { Student::destroy($id); return redirect('student')->with('flash_message', 'Student deleted!'); } } |



Create Model
Model is used to get the data from the database.
Create the Model name which is Student
1 | php artisan make:model Student |
After Model is Created the look like this. Code inside Model Class (app\Models\)
Change it as like this
Add the Namespace above
namespace App\Models;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Student extends Model { protected $table = 'students'; protected $primaryKey = 'id'; protected $fillable = ['name', 'address', 'mobile']; use HasFactory; } |
Create Views
Create a Folder inside the resources-views
inside the views folder create the students folder and layout folder
In Laravel you have create the pages using pagename.blade.php
Create pages
layout.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <!DOCTYPE html> <html> <head> <title>Student Laravel 9 CRUD</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> </head> <body> <div class="container"> @yield('content') </div> </body> </html> |
index.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 | @extends('students.layout') @section('content') <div class="container"> <div class="row"> <div class="col-md-9"> <div class="card"> <div class="card-header"> <h2>Laravel 9 Crud</h2> </div> <div class="card-body"> <a href="{{ url('/student/create') }}" class="btn btn-success btn-sm" title="Add New Student"> <i class="fa fa-plus" aria-hidden="true"></i> Add New </a> <br/> <br/> <div class="table-responsive"> <table class="table"> <thead> <tr> <th>#</th> <th>Name</th> <th>Address</th> <th>Mobile</th> <th>Actions</th> </tr> </thead> <tbody> @foreach($students as $item) <tr> <td>{{ $loop->iteration }}</td> <td>{{ $item->name }}</td> <td>{{ $item->address }}</td> <td>{{ $item->mobile }}</td> <td> <a href="{{ url('/student/' . $item->id) }}" title="View Student"><button class="btn btn-info btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View</button></a> <a href="{{ url('/student/' . $item->id . '/edit') }}" title="Edit Student"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</button></a> <form method="POST" action="{{ url('/student' . '/' . $item->id) }}" accept-charset="UTF-8" style="display:inline"> {{ method_field('DELETE') }} {{ csrf_field() }} <button type="submit" class="btn btn-danger btn-sm" title="Delete Student" onclick="return confirm("Confirm delete?")"><i class="fa fa-trash-o" aria-hidden="true"></i> Delete</button> </form> </td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> </div> @endsection |
create.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @extends('students.layout') @section('content') <div class="card"> <div class="card-header">Students Page</div> <div class="card-body"> <form action="{{ url('student') }}" method="post"> {!! csrf_field() !!} <label>Name</label></br> <input type="text" name="name" id="name" class="form-control"></br> <label>Address</label></br> <input type="text" name="address" id="address" class="form-control"></br> <label>Mobile</label></br> <input type="text" name="mobile" id="mobile" class="form-control"></br> <input type="submit" value="Save" class="btn btn-success"></br> </form> </div> </div> @stop |
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 | @extends('students.layout') @section('content') <div class="card"> <div class="card-header">Contactus Page</div> <div class="card-body"> <form action="{{ url('student/' .$students->id) }}" method="post"> {!! csrf_field() !!} @method("PATCH") <input type="hidden" name="id" id="id" value="{{$students->id}}" id="id" /> <label>Name</label></br> <input type="text" name="name" id="name" value="{{$students->name}}" class="form-control"></br> <label>Address</label></br> <input type="text" name="address" id="address" value="{{$students->address}}" class="form-control"></br> <label>Mobile</label></br> <input type="text" name="mobile" id="mobile" value="{{$students->mobile}}" class="form-control"></br> <input type="submit" value="Update" class="btn btn-success"></br> </form> </div> </div> @stop |
show.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | @extends('students.layout') @section('content') <div class="card"> <div class="card-header">Students Page</div> <div class="card-body"> <div class="card-body"> <h5 class="card-title">Name : {{ $students->name }}</h5> <p class="card-text">Address : {{ $students->address }}</p> <p class="card-text">Mobile : {{ $students->mobile }}</p> </div> </hr> </div> </div> |
Routes
Pages are Manage through routes. If you are crud system simple you can add it the routes one line look like this
1 | Route::resource("/student", StudentController::class); |
You have to add the ControllerNameSpace
use App\Http\Controllers\StudentController;
1 2 3 4 5 6 7 8 9 | <?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::get('/', function () { return view('welcome'); }); Route::resource("/student", StudentController::class); |
i have attached the video link below. which will do this tutorials step by step.