Laravel Laravel 7

To-Do Application in Laravel 7

Pinterest LinkedIn Tumblr

Step 1: Install Laravel 7

first of all, we need to get fresh Laravel 7 version application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel todoApp

Open your project in vs code
Configure your database (.env file)

[email protected]
php artisan make:migration create_tasks_table --create=tasks

Open migration file Put this line inside of migration table

public function up()
        Schema::create('tasks', function (Blueprint $table) {

Now Migrate

php artisan migrate

Create a Task Model

php artisan make:model Task

Now define in routes


use Illuminate\Support\Facades\Route;
use App\Task;
use Illuminate\Http\Request;

| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!

Route::get('/', function () {
    $tasks = Task::orderBy('created_at', 'asc')->get();

    return view('tasks', [
        'tasks' => $tasks

 * Add A New Task
Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255|min:5',

    if ($validator->fails()) {
        return redirect('/')

    $task = new Task;
    $task->name = $request->name;
    return redirect('/');

 * Delete An Existing Task
Route::delete('/task/{id}', function ($id) {
    return redirect('/');

Create app.blade.php file inside of views/layouts/app.blade.php

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel To Do List</title>
    <!-- Fonts -->
    <link href="" rel='stylesheet' type='text/css'>
    <link href=",300,400,700" rel='stylesheet' type='text/css'>
    <!-- Styles -->
    <link href="" rel="stylesheet">
        body {
            font-family: 'Lato';
        .fa-btn {
            margin-right: 6px;
<body id="app-layout">
    <nav class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header">
                <!-- Branding Image -->
                <a class="navbar-brand" href="{{ url('/') }}">
                    Real Programmer

    <!-- JavaScripts -->
    <script src=""></script>
    <script src=""></script>

Create a new file tasks.blade.php inside of views folder


    <div class="container">
        <div class="col-sm-offset-2 col-sm-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    New Task

                <div class="panel-body">
                    <!-- Display Validation Errors -->

                    <!-- New Task Form -->
                    <form action="{{ url('task')}}" method="POST" class="form-horizontal">
                        {{ csrf_field() }}

                        <!-- Task Name -->
                        <div class="form-group">
                            <label for="task-name" class="col-sm-3 control-label">Task</label>

                            <div class="col-sm-6">
                                <input type="text" name="name" id="task-name" class="form-control" value="{{ old('task') }}">

                        <!-- Add Task Button -->
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-6">
                                <button type="submit" class="btn btn-default">
                                    <i class="fa fa-btn fa-plus"></i>Add Task

            <!-- Current Tasks -->
            @if (count($tasks) > 0)
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Current Tasks

                    <div class="panel-body">
                        <table class="table table-striped task-table">
                                @foreach ($tasks as $task)
                                        <td class="table-text"><div>{{ $task->name }}</div></td>

                                        <!-- Task Delete Button -->
                                            <form action="{{ url('task/'.$task->id) }}" method="POST">
                                                {{ csrf_field() }}
                                                {{ method_field('DELETE') }}

                                                <button type="submit" class="btn btn-danger">
                                                    <i class="fa fa-btn fa-trash"></i>Delete

Create errors.blade.php inside of the common folder

@if (count($errors) > 0)
    <!-- Form Error List -->
    <div class="alert alert-danger">
        <strong>Whoops! Something went wrong!</strong>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>

Run server

php artisan serve

Write A Comment

Open chat
Hey Visitor,

How can I help you?