【发布时间】:2019-01-03 14:07:31
【问题描述】:
我刚刚添加了一个类别服务(类别名称:Like),但是当我转到服务列表(在用户面板中)时,更多类别出现在 Like 类别之前。 Please see this video for a better understanding of my problem:
Serviceslist.blade.php 代码(在视图文件夹中):
@extends('user.layouts.master')
@section('site_title', 'Service List')
@section('page_title')
<i class="fa fa-list-ol"></i> @lang('slide.serviceslist')
@endsection
@section('body')
<div class="row">
<div class="col-md-12">
@foreach($categories as $category)
<div class="card">
<div class="card-header bg-dark text-white">
@if(!empty($category->category)) {{ $category->category->name }} @endif
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Sevice code</th>
<th>Service name</th>
<th>Price</th>
<th>min</th>
<th>max</th>
</tr>
</thead>
<tbody>
@php
$items = \App\ServicePrice::where('category_id', $category->category_id)->where('user_id', Auth::id())->get();
@endphp
@foreach($items as $item)
@if(!empty($item->service))
<tr>
<td> {{$item->service->id}}</td>
<td> {{$item->service->name}}</td>
<td>{{ $item->price }}</td>
<td>{{ $item->service->min }}</td>
<td>{{ $item->service->max }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endforeach
</div>
</div>
@endsection
和服务列表控制器:
public function serviceList(){
$categories = ServicePrice::where('user_id', Auth::id())->distinct()-
>get(['category_id']);
return view('user.serviceList', compact('categories'));
}
【问题讨论】:
-
假设
$categories包含多个类别,但名称为空。或者也许是一件神奇的事情。 -
我在phpmyadmin中查看了分类表,只有“Like”分类。
标签: javascript php laravel