Created
January 2, 2016 07:28
-
-
Save trq/1cb0f7ef4913232fb962 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Repositories\TaskRepository; | |
class TaskController extends Controller | |
{ | |
/** | |
* @var TaskRepository | |
*/ | |
protected $tasks; | |
/** | |
* Create a new controller instance. | |
* | |
* @param TaskRepository $tasks | |
*/ | |
public function __construct(TaskRepository $tasks) | |
{ | |
$this->middleware('auth'); | |
$this->tasks = $tasks; | |
} | |
/** | |
* Display a list of all of the user's task. | |
* | |
* @param Request $request | |
* | |
* @return Response | |
*/ | |
public function index(Request $request) | |
{ | |
return view('tasks.index', [ | |
'tasks' => $this->tasks->forUser($request->user()) | |
]); | |
} | |
/** | |
* Create a new task. | |
* | |
* @param Request $request | |
* | |
* @return Response | |
*/ | |
public function store(Request $request) | |
{ | |
$this->validate($request, [ | |
'name' => 'required|max:255', | |
]); | |
// Create The Task... | |
$request->user()->tasks()->create([ | |
'name' => $request->name, | |
]); | |
return redirect('/tasks'); | |
} | |
/** | |
* Destroy the given task. | |
* | |
* @param Task $task | |
* | |
* @return Response | |
*/ | |
public function destroy(Task $task) | |
{ | |
$this->authorize('destroy', $task); | |
$task->delete(); | |
return redirect('/tasks'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment