image alt

How to make a ToDo App

blog image

Laravel 8 PHP Tutorial Series 

Tutorial 03

How to make a ToDo list application using Laravel?

Here we will help you develop a simple ToDo application with simple functions.

Part 01 - PHP Laravel Beginner tutorial | ToDo App - Tutorial 03 (Part 1) - YouTube

Part 02 - PHP Laravel Beginner tutorial | ToDo App - Tutorial 03 (Part 2) - YouTube

Some code segments that will come in handy :

//Routes

Route::prefix('/todo')->group(function (){

  Route::get('/', [TodoController::class, "index"])->name('todo');

  Route::post('/store', [TodoController::class, "store"])->name('todo.store');

  Route::get('/{task_id}/delete', [TodoController::class, "delete"])->name('todo.delete');

  Route::get('/{task_id}/done', [TodoController::class, "done"])->name('todo.done');

});

//Migrations

Schema::create('todos', function (Blueprint $table) {

  $table->id();

  $table->string('title')->nullable();

  $table->integer('done')->default(0);

  $table->timestamps();

});

 

 

//Model

class Todo extends Model

{

  use HasFactory;

  protected $fillable = [

    'title',

    'done',

  ];

}

 

//Controller

class TodoController extends Controller

{

  protected $task;

  public function __construct()

  {

    $this->task = new Todo();

  }

  public function index()

  {

    $response['tasks'] = $this->task->all();

    return view('pages.todo.index')->with($response);

  }

  public function store(Request $request)

  {

    $this->task->create($request->all());

    return redirect()->back();

  }

  public function delete($task_id)

  {

    $task = $this->task->find($task_id);

    $task->delete();

    return redirect()->back();

  }

  public function done($task_id)

  {

    $task = $this->task->find($task_id);

    $task->done = 1;

    $task->update();

    return redirect()->back();

  }

}

Facebook   : https://www.facebook.com/CyberElysium

Instagram   : https://www.instagram.com/cyber_elysium/

Twitter     : https://twitter.com/CyberElysium

LinkedIn   : https://www.linkedin.com/company/CyberElysium

Visit our website for more details: https://cyberelysium.com/

Thanks for reading ❤

Ready to grow your business digitally?