'Added Plan presenter'

This commit is contained in:
2023-12-11 11:35:07 +03:00
parent ed24c3e104
commit dfc6b7b5c8
4 changed files with 34 additions and 6 deletions

View File

@@ -1,11 +1,13 @@
<?php
namespace App\Models;
use Laracasts\Presenter\PresentableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
use App\Models\PlanLike;
use App\Presenters\PlanPresenter;
use Illuminate\Database\Eloquent\Casts\Attribute;
use CyrildeWit\EloquentViewable\InteractsWithViews;
use CyrildeWit\EloquentViewable\Contracts\Viewable;
@@ -14,6 +16,8 @@ class Plan extends Model implements Viewable
{
use HasFactory;
use InteractsWithViews;
use PresentableTrait;
protected $withCount = [
'likes',
@@ -28,6 +32,9 @@ class Plan extends Model implements Viewable
];
protected $presenter = PlanPresenter::class;
public function author()
{
return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id');

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Presenters;
use Illuminate\Support\Facades\Storage;
use App\Models\Plan;
use Laracasts\Presenter\Presenter;
class PlanPresenter extends Presenter
{
public function getAuthorPhoto()
{
$author = $this->getAuthor();
return Storage::url($author->profile_photo_path);
}
public function getAuthor()
{
return $this->author->first();
}
}

View File

@@ -49,7 +49,7 @@
<a href="#"><svg width="24" height="21"><use xlink:href="#HeartPath"></use></svg></a>
</div>
@php
$author = $plan->author()->first();
$author = $plan->present()->getAuthor;
@endphp
<a href="{{ route('profile.show', $author) }}" style="color:var(--main_fcolor)">

View File

@@ -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();