Exemplo n.º 1
0
<?php

use App\Todos;
use Illuminate\Http\Request;
/**
* Render main view
*/
$app->get('/', function () {
    return view('todos.index');
});
/**
* Get all todos
*/
$app->get('todos', function () {
    $todos = Todos::orderBy('created_at', 'DESC')->paginate(5)->toArray();
    $remaining = Todos::where('completed', 0)->count();
    return ['todos' => $todos, 'remaining' => $remaining];
});
/**
* Create todo
*/
$app->post('add-todo', function (Request $request) {
    Todos::create($request->all());
});
/**
* Delete todo
*/
$app->post('todos/delete/{id}', function ($id) {
    Todos::destroy($id);
});
/**
Exemplo n.º 2
0
 public function allTodos()
 {
     $todos = Todos::orderBy('created_at', 'DESC')->paginate(5)->toArray();
     $remaining = Todos::where('completed', 0)->count();
     return ['todos' => $todos, 'remaining' => $remaining];
 }