forked from eatvio/eatvio-infra
'Added Plan presenter'
This commit is contained in:
@@ -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');
|
||||
|
||||
22
app/Presenters/PlanPresenter.php
Normal file
22
app/Presenters/PlanPresenter.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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)">
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user