根据状态隐藏记录
hide a record according to status
如果状态为== 'Terminado',我需要隐藏一条记录。
用if条件搞定了,不知道怎么应用
blade.php
<tbody>
@foreach($registros as $registro)
@if($registro->sucursal == Auth::user()->sucursal)
@if($registro->empleado == Auth::user()->tipo)
<tr>
<td>{{$registro->cliente}}</td>
<td>{{$registro->tipo}}</td>
<td>
<div class="progress br-30">
@if($registro->estado == 'Ingresado')
<div class="progress-bar br-30 bg-primary" role="progressbar" style="width: 20%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif($registro->estado == 'Envío de Prespuesto')
<div class="progress-bar br-30 bg-secondry" role="progressbar" style="width: 40%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif($registro->estado == 'Anticipo Recibido')
<div class="progress-bar br-30 bg-warning" role="progressbar" style="width: 60%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'En Reparación')
<div class="progress-bar br-30 bg-danger" role="progressbar" style="width: 80%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'Terminado')
<div class="progress-bar br-30 bg-success" role="progressbar" style="width: 100%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'Cancelado')
<div class="progress-bar br-30 bg-danger" role="progressbar" style="width: 100%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@endif
</div>
</td>
<td>{{$registro->estado}}</td>
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
<td> @if($registro->presupuesto == null) No Aplicado @else ${{$registro->presupuesto}} @endif</td>
<td class="text-center">
<div class="dropdown custom-dropdown">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal"><circle cx="12" cy="12" r="1"></circle><circle cx="19" cy="12" r="1"></circle><circle cx="5" cy="12" r="1"></circle></svg>
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink1">
<a class="dropdown-item" href="{{route('detalle', $registro)}}">Ver</a>
<a href="{{route('editar', $registro)}}" class="dropdown-item" href="javascript:void(0);">Actualizar</a>
<a class="dropdown-item" href="javascript:void(0);">Borrar</a>
</div>
</div>
</td>
</tr>
@elseif($registro->estado == 'Terminado')
@endif
@endif
@endforeach
</tbody>
如果状态字段为 == Terminado
,foreach 不应显示
但如果它没有完成状态,如果它应该显示记录
控制器:
public function registros(){
if (Auth::guest()) return redirect('/login');
$data = [
'category_name' => 'datatable',
'page_name' => 'multiple_tables',
'has_scrollspy' => 0,
'scrollspy_offset' => '',
'fechax' => Carbon::now(),
];
$registros = \App\Models\Registro::All();
return view('pages.tables.table_dt_multiple_tables',compact('registros'))->with($data);
}
附加blade控制器
附加 blade 控制器
求助
您可以在循环中使用 continue
来跳过当前项目。
@foreach($registros as $registro)
@if ($registro->estado == 'Terminado')
@continue
@endif
<!-- Rest of the template -->
@endforeach
但是,我宁愿在控制器中处理它。
class RegistroController extends Controller
{
public function registros(){
if (Auth::guest()) return redirect('/login');
$data = [
'category_name' => 'datatable',
'page_name' => 'multiple_tables',
'has_scrollspy' => 0,
'scrollspy_offset' => '',
'fechax' => Carbon::now(),
];
$registros = \App\Models\Registro::where('estado', '<>', 'Terminado')->get();
return view('pages.tables.table_dt_multiple_tables', compact('registros'))->with($data);
}
}
您也可以在控制器中执行此操作,在其中进行查询:
Registro::where('estado', '!=' , 'Terminado')->get();
PS:我假设您的型号名称是 Registro
如果记录状态为 'Terminado',您只想从 foreach 中排除?
blade
@foreach($registros as $registro)
@if($registro->status != 'Terminado')
//.....
或者在控制器中,您可以在查询数据库时排除这些行。
对于结束状态和其他情况,还有另一种方法,这取决于您的要求,那就是 SoftDeletes。如果在大多数情况下不需要此完成状态,或者只是在准时的情况下您可以检索此数据,也许使用它可以帮助您从查询中排除。
如果状态为== 'Terminado',我需要隐藏一条记录。
用if条件搞定了,不知道怎么应用
blade.php
<tbody>
@foreach($registros as $registro)
@if($registro->sucursal == Auth::user()->sucursal)
@if($registro->empleado == Auth::user()->tipo)
<tr>
<td>{{$registro->cliente}}</td>
<td>{{$registro->tipo}}</td>
<td>
<div class="progress br-30">
@if($registro->estado == 'Ingresado')
<div class="progress-bar br-30 bg-primary" role="progressbar" style="width: 20%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif($registro->estado == 'Envío de Prespuesto')
<div class="progress-bar br-30 bg-secondry" role="progressbar" style="width: 40%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif($registro->estado == 'Anticipo Recibido')
<div class="progress-bar br-30 bg-warning" role="progressbar" style="width: 60%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'En Reparación')
<div class="progress-bar br-30 bg-danger" role="progressbar" style="width: 80%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'Terminado')
<div class="progress-bar br-30 bg-success" role="progressbar" style="width: 100%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@elseif ($registro->estado == 'Cancelado')
<div class="progress-bar br-30 bg-danger" role="progressbar" style="width: 100%" aria-valuenow="67" aria-valuemin="0" aria-valuemax="100"></div>
@endif
</div>
</td>
<td>{{$registro->estado}}</td>
<td>{{ ($registro->created_at->format('d-m-Y')) }}</td>
<td> @if($registro->presupuesto == null) No Aplicado @else ${{$registro->presupuesto}} @endif</td>
<td class="text-center">
<div class="dropdown custom-dropdown">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal"><circle cx="12" cy="12" r="1"></circle><circle cx="19" cy="12" r="1"></circle><circle cx="5" cy="12" r="1"></circle></svg>
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink1">
<a class="dropdown-item" href="{{route('detalle', $registro)}}">Ver</a>
<a href="{{route('editar', $registro)}}" class="dropdown-item" href="javascript:void(0);">Actualizar</a>
<a class="dropdown-item" href="javascript:void(0);">Borrar</a>
</div>
</div>
</td>
</tr>
@elseif($registro->estado == 'Terminado')
@endif
@endif
@endforeach
</tbody>
如果状态字段为 == Terminado
,foreach 不应显示但如果它没有完成状态,如果它应该显示记录
控制器:
public function registros(){
if (Auth::guest()) return redirect('/login');
$data = [
'category_name' => 'datatable',
'page_name' => 'multiple_tables',
'has_scrollspy' => 0,
'scrollspy_offset' => '',
'fechax' => Carbon::now(),
];
$registros = \App\Models\Registro::All();
return view('pages.tables.table_dt_multiple_tables',compact('registros'))->with($data);
}
附加blade控制器 附加 blade 控制器 求助
您可以在循环中使用 continue
来跳过当前项目。
@foreach($registros as $registro)
@if ($registro->estado == 'Terminado')
@continue
@endif
<!-- Rest of the template -->
@endforeach
但是,我宁愿在控制器中处理它。
class RegistroController extends Controller
{
public function registros(){
if (Auth::guest()) return redirect('/login');
$data = [
'category_name' => 'datatable',
'page_name' => 'multiple_tables',
'has_scrollspy' => 0,
'scrollspy_offset' => '',
'fechax' => Carbon::now(),
];
$registros = \App\Models\Registro::where('estado', '<>', 'Terminado')->get();
return view('pages.tables.table_dt_multiple_tables', compact('registros'))->with($data);
}
}
您也可以在控制器中执行此操作,在其中进行查询:
Registro::where('estado', '!=' , 'Terminado')->get();
PS:我假设您的型号名称是 Registro
如果记录状态为 'Terminado',您只想从 foreach 中排除? blade
@foreach($registros as $registro)
@if($registro->status != 'Terminado')
//.....
或者在控制器中,您可以在查询数据库时排除这些行。 对于结束状态和其他情况,还有另一种方法,这取决于您的要求,那就是 SoftDeletes。如果在大多数情况下不需要此完成状态,或者只是在准时的情况下您可以检索此数据,也许使用它可以帮助您从查询中排除。