fixed page detail
This commit is contained in:
parent
d910da229b
commit
71c675fb84
|
|
@ -236,6 +236,23 @@ function currency_format($price, string $currency = '', string $value = '', bool
|
||||||
return CurrencyService::getInstance()->format($price, $currency, $value, $format);
|
return CurrencyService::getInstance()->format($price, $currency, $value, $format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间格式化
|
||||||
|
*
|
||||||
|
* @param null $datetime
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
function time_format($datetime = null)
|
||||||
|
{
|
||||||
|
$format = 'Y-m-d H:i:s';
|
||||||
|
if ($datetime instanceof Illuminate\Support\Carbon) {
|
||||||
|
return $datetime->format($format);
|
||||||
|
} elseif (is_int($datetime)) {
|
||||||
|
return date($format, $datetime);
|
||||||
|
}
|
||||||
|
return date($format);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片缩放
|
* 图片缩放
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,17 @@
|
||||||
namespace Beike\Shop\Http\Controllers;
|
namespace Beike\Shop\Http\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use Beike\Models\Page;
|
||||||
|
use Beike\Shop\Http\Resources\PageDetail;
|
||||||
|
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
public function show()
|
public function show(Page $page)
|
||||||
{
|
{
|
||||||
|
$page->load('description');
|
||||||
|
$data = [
|
||||||
|
'page' => (new PageDetail($page))->jsonSerialize()
|
||||||
|
];
|
||||||
|
dd($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PageDetail.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-08-11 18:45:02
|
||||||
|
* @modified 2022-08-11 18:45:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Beike\Shop\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class PageDetail extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
$description = $this->description;
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'title' => $description->title,
|
||||||
|
'content' => $description->content,
|
||||||
|
'meta_title' => $description->meta_title,
|
||||||
|
'meta_description' => $description->meta_description,
|
||||||
|
'meta_keyword' => $description->meta_keyword,
|
||||||
|
'created_at' => time_format($this->created_at),
|
||||||
|
'updated_at' => time_format($this->updated_at),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue