Example #1
0
use App\Todos;
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('todos', function () {
    return Todos::all();
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
    //
});
* Delete todo
*/
$app->post('todos/delete/{id}', function ($id) {
    Todos::destroy($id);
});
/**
* Complete todo
*/
$app->post('todos/complete/{id}/{completed}', function ($id, $completed) {
    Todos::where('id', $id)->update(['completed' => $completed]);
});
/**
* Update todo
*/
$app->post('update/{id}', function (Request $request, $id) {
    Todos::where('id', $id)->update(['name' => $request->input('name'), 'description' => $request->input('description'), 'completed' => $request->input('completed')]);
});
/**
* Render add todo
*/
$app->get('add-form', function () {
    return view('todos.templates.add_form');
});
/**
* Render update todo
*/
$app->get('edit-form', function () {
    return view('todos.templates.edit_form');
});
/**
* Todos table
 public function update($id, TodosRequest $request)
 {
     Todos::findorFail($id)->update($request->all());
     return redirect('todos');
 }
 public function update(Request $request, $id)
 {
     Todos::where('id', $id)->update(['name' => $request->input('name'), 'body' => $request->input('body'), 'completed' => $request->input('completed')]);
 }
 /**
  * Sync up the list of tags in the database.
  *
  * @param Todos $todos
  * @param array $tags
  */
 private function syncTags(Todos $todos, array $tags)
 {
     $todos->tags()->sync($tags);
 }