添加面包屑library

This commit is contained in:
Edward Yang 2023-02-01 10:03:20 +08:00
parent 1220abb705
commit bf632700a0
3 changed files with 75 additions and 2 deletions

View File

@ -154,9 +154,9 @@ function type_route($type, $value): string
} elseif ($type == 'custom') {
if (Str::startsWith($value, ['http://', 'https://'])) {
return $value;
} else {
return "//{$value}";
}
return "//{$value}";
}
return '';

View File

@ -0,0 +1,69 @@
<?php
/**
* Breadcrumb.php
*
* @copyright 2023 beikeshop.com - All Rights Reserved
* @link https://beikeshop.com
* @author Edward Yang <yangjin@guangda.work>
* @created 2023-02-01 09:38:33
* @modified 2023-02-01 09:38:33
*/
namespace Beike\Libraries;
use Illuminate\Contracts\View\View;
class Breadcrumb
{
public array $breadcrumbs;
/**
* Create a new component instance.
*
* @return void
* @throws \Exception
*/
public function __construct()
{
$this->breadcrumbs[] = [
'title' => trans('shop/common.home'),
'url' => shop_route('home.index'),
];
}
/**
* 获取 Breadcrumb 实例
* @return Breadcrumb
*/
public static function getInstance(): self
{
return new self;
}
/**
* 添加面包屑节点链接
*
* @param $url
* @param $text
* @return Breadcrumb
*/
public function addLink($url, $text): self
{
$this->breadcrumbs[] = [
'url' => $url,
'title' => $text,
];
return $this;
}
/**
* Get the view / contents that represent the component.
*
* @return View|
*/
public function render(): View
{
return view('components.breadcrumbs', ['breadcrumbs' => collect($this->breadcrumbs)]);
}
}

View File

@ -21,6 +21,10 @@ class BrandController extends Controller
public function show(int $id)
{
$brand = BrandRepo::find($id);
if (empty($brand)) {
return redirect(shop_route('brands.index'));
}
$products = $brand->products()
->with([
'masterSku',