Refactor url link and label for brand、page and page category.

This commit is contained in:
Edward Yang 2023-03-15 15:19:25 +08:00
parent 68231b0538
commit a75d795098
4 changed files with 25 additions and 1 deletions

View File

@ -24,4 +24,12 @@ class Brand extends Base
{
return $this->hasMany(Product::class);
}
public function getUrlAttribute()
{
$url = shop_route('brands.show', ['id' => $this->id]);
$filters = hook_filter('model.brand.url', ['url' => $url, 'brand' => $this]);
return $filters['url'] ?? '';
}
}

View File

@ -46,4 +46,12 @@ class Page extends Base
{
return $this->belongsToMany(Product::class, PageProduct::class, 'page_id', 'product_id')->withTimestamps();
}
public function getUrlAttribute()
{
$url = shop_route('pages.show', ['page' => $this]);
$filters = hook_filter('model.page.url', ['url' => $url, 'page' => $this]);
return $filters['url'] ?? '';
}
}

View File

@ -48,4 +48,12 @@ class PageCategory extends Model
{
return $this->hasMany(Page::class, 'page_category_id');
}
public function getUrlAttribute()
{
$url = shop_route('page_categories.show', ['page_category' => $this]);
$filters = hook_filter('model.page_category.url', ['url' => $url, 'page_category' => $this]);
return $filters['url'] ?? '';
}
}

View File

@ -23,7 +23,7 @@
<div class="row">
@foreach ($brand as $item)
<div class="text-center col-6 col-md-4 col-lg-2 mt-2">
<a href="{{ shop_route('brands.show', [$item['id']]) }}">
<a href="{{ type_route('brand', $item['id']) }}">
<div class="brand-item">
<img src="{{ $item['logo'] }}" class="img-fluid" alt="{{ $item['name'] }}">
</div>