Created
June 6, 2020 13:37
-
-
Save JethroPasco/3b732a58a3361edbe21dae69effefb97 to your computer and use it in GitHub Desktop.
Revisions
-
JethroPasco created this gist
Jun 6, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <?php namespace App\Http\Controllers; use App\Task; use App\Http\Responses; use App\Http\Controllers\Controller; class DashboardController extends Controller { public function __invoke($id) { $tasks = Task::all(); return new DashboardResponse($tasks); } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ <?php namespace App\Http\Responses; use Illuminate\Contracts\Support\Responsable; class DashboardResponse implements Responsable { protected $tasks; public function __construct($tasks) { $this->$tasks = $tasks; } public function status() { return 200; } public function toResponse() { $data = $this->prepareData(); if (request()->ajax()) { return response()->json($data); } return view('dashboard', $data); } protected function prepareData() { return [ 'tasks' => $this->tasks ]; } }