如何在 PHP 中仅显示未来的约会



我正在尝试设计一个健康预约管理器。我尝试仅在索引边栏选项卡中显示未来的约会,但也有一个按钮,我可以单击该按钮以查看过去的约会。我遇到的是,在索引边栏选项卡中,显示了过去和将来的约会。当我单击按钮时,还会显示约会(过去和将来(。

我同时连接了 CitaController 和索引刀片:

CitaController的代码:

public function index()
{

$citas = Cita::all();
return view('citas/index',['citas'=>$citas]);
}

索引视图:

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Citas</div>
<div class="panel-body">
@include('flash::message')
{!! Form::open(['route' => 'citas.create', 'method' => 'get']) !!}
{!!   Form::submit('Crear cita', ['class'=> 'btn btn-primary'])!!}
{!! Form::close() !!}
{!! Form::open(['route' => 'citas.index', 'method'=>'get']) !!}
<div class="form-group">
<br>
{!! Form::open(['route' => ['citas.show','id'], 'method' => 'get']) !!}
{!!   Form::submit('todas las citas', ['class'=> 'btn btn-warning'])!!}
{!! Form::close() !!}
<br><br>
<table class="table table-striped table-bordered">
<tr>
<th>Fecha</th>
<th>Medico</th>
<th>Paciente</th>
<th colspan="2">Localización</th>
<!--<td>Hospital</td>
<td>Consulta</td> -->
<th>Duración</th>
<th>Hora finalización</th>

<th colspan="2">Acciones</th>
</tr>
@foreach ($citas as $cita)

<tr>
<td>{{ $cita->fecha_hora }}</td>
<td>{{ $cita->medico->full_name }}</td>
<td>{{ $cita->paciente->full_name}}</td>
<td>{{ $cita->location->hospital}}</td>
<td>{{ $cita->location->consulta}}</td>
<td>{{ $cita->duracion}}</td>
<td>{{ $cita->hora_fin}}</td>

<td>
{!! Form::open(['route' => ['citas.edit',$cita->id], 'method' => 'get']) !!}
{!!   Form::submit('Editar', ['class'=> 'btn btn-warning'])!!}
{!! Form::close() !!}
</td>
<td>
{!! Form::open(['route' => ['citas.destroy',$cita->id], 'method' => 'delete']) !!}
{!!   Form::submit('Borrar', ['class'=> 'btn btn-danger' ,'onclick' => 'if(!confirm("¿Está seguro?"))event.preventDefault();'])!!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
@endsection

我感谢任何可能的帮助

可能(但有些丑陋的解决方案(

默认情况下,这将显示未来的约会,并在单击按钮后显示所有约会

刀片文件:

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Citas</div>
<div class="panel-body">
@include('flash::message')
{!! Form::open(['route' => 'citas.create', 'method' => 'get']) !!}
{!!   Form::submit('Crear cita', ['class'=> 'btn btn-primary'])!!}
{!! Form::close() !!}
{!! Form::open(['route' => 'citas.index', 'method'=>'get']) !!}
{!! Form::hidden('data', 'all') !!}
{!! Form::submit('Show cita', ['class'=> 'btn btn-primary'])!!}
{!! Form::close() !!}
<div class="form-group">
<br>
{!! Form::open(['route' => ['citas.show','id'], 'method' => 'get']) !!}
{!!   Form::submit('todas las citas', ['class'=> 'btn btn-warning'])!!}
{!! Form::close() !!}
<br><br>
<table class="table table-striped table-bordered">
<tr>
<th>Fecha</th>
<th>Medico</th>
<th>Paciente</th>
<th colspan="2">Localización</th>
<!--<td>Hospital</td>
<td>Consulta</td> -->
<th>Duración</th>
<th>Hora finalización</th>

<th colspan="2">Acciones</th>
</tr>
@foreach ($citas as $cita)

<tr>
<td>{{ $cita->fecha_hora }}</td>
<td>{{ $cita->medico->full_name }}</td>
<td>{{ $cita->paciente->full_name}}</td>
<td>{{ $cita->location->hospital}}</td>
<td>{{ $cita->location->consulta}}</td>
<td>{{ $cita->duracion}}</td>
<td>{{ $cita->hora_fin}}</td>

<td>
{!! Form::open(['route' => ['citas.edit',$cita->id], 'method' => 'get']) !!}
{!!   Form::submit('Editar', ['class'=> 'btn btn-warning'])!!}
{!! Form::close() !!}
</td>
<td>
{!! Form::open(['route' => ['citas.destroy',$cita->id], 'method' => 'delete']) !!}
{!!   Form::submit('Borrar', ['class'=> 'btn btn-danger' ,'onclick' => 'if(!confirm("¿Está seguro?"))event.preventDefault();'])!!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
@endsection

控制器

public function index()
{
if(isset(request()->input('data')) {
$citas = Cita::all();
} else {
$citas= Cita::where('appointment_date', '>', CarbonCarbon::now())->get();
}
return view('citas/index',['citas'=>$citas]);
}

最新更新