forked from eatvio/eatvio-infra
added accordion toggle to show plan
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
<?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;
|
||||
use CyrildeWit\EloquentViewable\InteractsWithViews;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
|
||||
class Plan extends Model implements Viewable
|
||||
{
|
||||
@@ -18,7 +19,6 @@ class Plan extends Model implements Viewable
|
||||
use InteractsWithViews;
|
||||
use PresentableTrait;
|
||||
|
||||
|
||||
protected $withCount = [
|
||||
'likes',
|
||||
'comments'
|
||||
@@ -31,10 +31,8 @@ class Plan extends Model implements Viewable
|
||||
'packet3_options' => 'array',
|
||||
];
|
||||
|
||||
|
||||
protected $presenter = PlanPresenter::class;
|
||||
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id');
|
||||
@@ -63,12 +61,12 @@ class Plan extends Model implements Viewable
|
||||
{
|
||||
$result = [];
|
||||
for ($i = 1; $i <= $this->packets_count; $i++) {
|
||||
$key = "packet" . $i . "_options";
|
||||
$key = 'packet' . $i . '_options';
|
||||
|
||||
// $data = $this->unserializeOptionsObj($this->$key);
|
||||
$data = $this->$key;
|
||||
if (!is_null($data)) {
|
||||
$result = array_merge($result, data_get($data, "items", []));
|
||||
$result = array_merge($result, data_get($data, 'items', []));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +79,7 @@ class Plan extends Model implements Viewable
|
||||
$data = $this->type;
|
||||
|
||||
return new Attribute(
|
||||
get: fn () => array_keys($data),
|
||||
get: fn() => array_keys($data),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,18 +87,18 @@ class Plan extends Model implements Viewable
|
||||
{
|
||||
$result = 0;
|
||||
for ($i = 1; $i <= $this->packets_count; $i++) {
|
||||
$key = "packet" . $i . "_options";
|
||||
$key = 'packet' . $i . '_options';
|
||||
// dd($this->$key);
|
||||
// $data = $this->unserializeOptionsObj($this->$key);
|
||||
$data = $this->$key;
|
||||
if (!is_null($data)) {
|
||||
$curPrice = (int)data_get($data, "price", 0);
|
||||
$result = $curPrice > $result ? $curPrice : $result ;
|
||||
$curPrice = (int) data_get($data, 'price', 0);
|
||||
$result = $curPrice > $result ? $curPrice : $result;
|
||||
}
|
||||
}
|
||||
|
||||
return new Attribute(
|
||||
get: fn () => $result,
|
||||
get: fn() => $result,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,4 +126,14 @@ class Plan extends Model implements Viewable
|
||||
}
|
||||
return json_decode(stripslashes($str), true);
|
||||
}
|
||||
|
||||
public function scopeByNegative(Builder $query)
|
||||
{
|
||||
return static::comments()->where('grade', '<=', '3');
|
||||
}
|
||||
|
||||
public function scopeByPositive(Builder $query)
|
||||
{
|
||||
return static::comments()->where('grade', '>', '3');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user