Todo Application in Laravel

By | March 5, 2019

1.Create Project in Laravel

Composer create-project laravel/laravel todolist

2.Create CRUD Controller

php artisan make:controller TodosController –resource

3.Route setup of CRUD Controller

routes/web.php

Route::get('/','TodosController@index');
Route::resource('todo', 'TodosController');

4.Create Database todolist

localhost/phpmyadmin

create database todolist

5.Create Model Todo

php artisan make:model Todo -m

6.Create Todo Table Structure

database/migrations/_create_todos_table.php

database/migrations/_create_todos_table.php

public function up()
{
	Schema::create('todos', function (Blueprint $table){
		$table->increments('id');
		$table->string('text');
		$table->mediumText('body');
		$table->string('due');
		$table->timestamps();
	});
}

7.Database Configuration

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=todolist
DB_USERNAME=root
DB_PASSWORD=

8.Configure Default String Length

app/Providers/AppServiceProvider.php

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;


public function boot()
{
	Schema::defaultStringLength(191);
}

9.Migrate with Database

php artisan migrate

10.Data Insert By Command Line

php artisan tinker

</p><p>$todo = new App\Todo();<br>       $todo->text='Todo One';<br>       $todo->body = 'This is my first todo';<br>       $todo->due = 'Monday May 7';<br>       $todo->save();</p><p>$todo = new App\Todo();<br>       $todo->text='Todo Two';<br>       $todo->body = 'This is my second todo';<br>       $todo->due = 'Tuesday May 8';<br>       $todo->save();</p><p>

11.Select All Data from Command Line


 </p><p>App\Todo::all();</p><cite> <br>

12.Select Specific Data from Command Line

>>> App\Todo::find(1);

13.Display All Data in index function

app/Http/Controllers/TodosController.php

use Illuminate\Http\Request;
use App\Todo;

class TodosController extends Controller
{
	public function index()
	{
		// $todos = Todo::all();
		$todos = Todo::orderBy('created_at', 'desc')->get();
		return view('todos.index')->with('todos', $todos);
	}
}
 

14.Create index.blade.php file for display index function

resources/views/todos/index.blade.php

@extends('layouts.app')

@section('content')
<h1>Todos</h1>
@if(count($todos) > 0)
	@foreach($todos as $todo)
		<div class="card">
			<h3><a href="todo/{{$todo->id}}">{{$todo->text}}</a></h3>
			<p class="text-danger">{{$todo->due}}</p>
		</div>
	@endforeach
@endif
@endsection

15.create app.blade.php for include css and container

resources/views/layouts/app.blade.php

<title>TodoList</title>
<link rel="stylesheet" href="/css/app.css">

<div class="container">
	@yield('content')
</div>

<footer id ="footer" class="footer">
	<p>copyright © 2017 TodoList</p>
</footer>

16.Display The Specific Data in show function

app/Http/Controllers/TodosController.php

use Illuminate\Http\Request;
use App\Todo;

class TodosController extends Controller
{
	public function show($id)
	{
		 $todos = Todo::find($id);
		return view('todos.index')->with('todos', $todos);
	}
}

17.Create show.blade.php file for display show function

resources/views/todos/show.blade.php

@extends('layouts.app')

@section('content')
<a href="/" class="btn btn-default">Go Back</a>
<h1>{{$todo->text}}</h1>
@endsection