You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.1 KiB
61 lines
1.1 KiB
<?php
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Application Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register all of the routes for 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.
|
|
|
|
|
*/
|
|
|
|
use App\Task;
|
|
use Illuminate\Http\Request;
|
|
|
|
Route::group(['middleware' => 'web'], function () {
|
|
|
|
/**
|
|
* Show Task Dashboard
|
|
*/
|
|
Route::get('/', function () {
|
|
return view('tasks', [
|
|
'tasks' => Task::orderBy('created_at', 'asc')->get()
|
|
]);
|
|
});
|
|
|
|
|
|
/**
|
|
* Add New Task
|
|
*/
|
|
Route::post('/task', function (Request $request) {
|
|
$validator = Validator::make($request->all(), [
|
|
'name' => 'required|max:255',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect('/')
|
|
->withInput()
|
|
->withErrors($validator);
|
|
}
|
|
|
|
$task = new Task;
|
|
$task->name = $request->name;
|
|
$task->save();
|
|
|
|
return redirect('/');
|
|
});
|
|
|
|
|
|
/**
|
|
* Delete Task
|
|
*/
|
|
Route::delete('/task/{id}', function ($id) {
|
|
Task::findOrFail($id)->delete();
|
|
|
|
return redirect('/');
|
|
});
|
|
|
|
});
|