From 94d6e6a4dcb6fb88dc606940a8a240260e6662ea Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Mon, 27 Apr 2020 11:06:12 +0200 Subject: [PATCH] todo front in work --- app/Http/Controllers/ToDoListController.php | 7 +++ app/Http/Resources/ToDoList.php | 2 +- app/Models/User.php | 10 ++-- resources/js/components/InputField.vue | 3 +- resources/js/components/Nav.vue | 2 +- resources/js/views/ToDoLists/ToDoList.vue | 50 +++++++++++++++++++ .../js/views/ToDoLists/ToDoListIndex.vue | 15 ++++-- resources/svg/list.svg | 11 ++++ tests/Feature/ToDoListsTest.php | 44 ++++++++++++++++ 9 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 resources/js/views/ToDoLists/ToDoList.vue create mode 100644 resources/svg/list.svg diff --git a/app/Http/Controllers/ToDoListController.php b/app/Http/Controllers/ToDoListController.php index 98fa2a3..e3ad9e2 100644 --- a/app/Http/Controllers/ToDoListController.php +++ b/app/Http/Controllers/ToDoListController.php @@ -8,6 +8,13 @@ use Illuminate\Http\Request; class ToDoListController extends Controller { + public function index() + { + $this->authorize('viewAny', ToDoList::class); + + return ToDoListResource::collection(request()->user()->toDoLists); + } + public function store() { $this->authorize('create', ToDoList::class); diff --git a/app/Http/Resources/ToDoList.php b/app/Http/Resources/ToDoList.php index 534445f..7de7c44 100644 --- a/app/Http/Resources/ToDoList.php +++ b/app/Http/Resources/ToDoList.php @@ -23,7 +23,7 @@ class ToDoList extends JsonResource 'data' => [ 'name' => $this->name, 'to_dos' => new ToDoCollection($this->toDos), - 'posted_by' => new UserResource($this->user), + 'posted_by' => new UserResource($this->author), 'last_updated' => $this->updated_at->diffForHumans(), // 'cover_image' => new ImageResource($this->coverImage), ] diff --git a/app/Models/User.php b/app/Models/User.php index 3d8cfcd..7d0fe28 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -59,6 +59,11 @@ class User extends Authenticatable return $this->hasMany(Memo::class); } + public function toDoLists() : HasMany + { + return $this->hasMany(ToDoList::class); + } + public function images(): MorphMany { return $this->morphMany(Image::class, 'imageable'); @@ -83,9 +88,4 @@ class User extends Authenticatable $userImage->path = 'images/default-cover.jpg'; }); } - - public function toDoLists(): HasMany - { - return $this->hasMany(ToDoList::class); - } } diff --git a/resources/js/components/InputField.vue b/resources/js/components/InputField.vue index 17b92b6..aff686b 100644 --- a/resources/js/components/InputField.vue +++ b/resources/js/components/InputField.vue @@ -1,5 +1,5 @@