From dfc6b7b5c814aac6519600195adc73cac0f5e4cc Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Mon, 11 Dec 2023 11:35:07 +0300 Subject: [PATCH] 'Added Plan presenter' --- app/Models/Plan.php | 7 +++++++ app/Presenters/PlanPresenter.php | 22 ++++++++++++++++++++++ resources/views/plan/index.blade.php | 2 +- resources/views/plan/show.blade.php | 9 ++++----- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 app/Presenters/PlanPresenter.php diff --git a/app/Models/Plan.php b/app/Models/Plan.php index b718016..20a25d3 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -1,11 +1,13 @@ belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); diff --git a/app/Presenters/PlanPresenter.php b/app/Presenters/PlanPresenter.php new file mode 100644 index 0000000..85fcf1e --- /dev/null +++ b/app/Presenters/PlanPresenter.php @@ -0,0 +1,22 @@ +getAuthor(); + + return Storage::url($author->profile_photo_path); + } + + public function getAuthor() + { + return $this->author->first(); + } +} diff --git a/resources/views/plan/index.blade.php b/resources/views/plan/index.blade.php index 14803f2..c0790fe 100644 --- a/resources/views/plan/index.blade.php +++ b/resources/views/plan/index.blade.php @@ -49,7 +49,7 @@ @php - $author = $plan->author()->first(); + $author = $plan->present()->getAuthor; @endphp diff --git a/resources/views/plan/show.blade.php b/resources/views/plan/show.blade.php index 473264f..ca3913f 100644 --- a/resources/views/plan/show.blade.php +++ b/resources/views/plan/show.blade.php @@ -1,10 +1,9 @@ @extends('layouts/eatvio') @php - $author = $plan->author()->first(); - $authorPhoto = Storage::url($author->profile_photo_path); - if(is_null($author->profile_photo_path)) { - $authorPhoto =$author->profile_photo_url; - } + + $author = $plan->present()->getAuthor; + + $authorPhoto = $plan->present()->getAuthorPhoto; $image = Storage::url($plan->image); $planViewsCount = views($plan)->unique()->count();