我需要检查schedules_id
是否等于请求schedules_id
,然后需要检查profile
'已预订'或'待处理'然后需要通过所有'已预订'{{1} } profile
值插入blade.php。我该怎么做,或者是否有其他方式或逻辑来做这件事,请告诉我我是Laravel的新手
我现在如何获取数据:
seat
blade.php
class PassengersController extends Controller
{
public function booking(Request $request)
{
//river is used to pass important params with flow of it from page to page
$seat = $request->seat;
$buses_id = $request->buses_id;
$schedules_id = $request->schedules_id;
$data = Buses::where('buses_id', $buses_id)->first();
$seat = json_decode($data->seat_layout, true);
$front = json_decode($data->front_layout, true);
$bookingSeat = Bookings::whereColumn('schedules_id', 'schedules_id')->get();
$bookingSeat = $bookingSeat->map(function ($bookSeat) {
$bookSeat->seat = explode(",", $bookSeat->seat);
return $bookSeat;
});
return view('frontend.booking', ['seat' => $seat, 'buses_id' => $buses_id, 'schedules_id' => $schedules_id, 'front' => $front, 'bookingSeet' => $bookingSeat]);
}
}
表
<div class="bus">
@foreach($seat as $key => $item)
@foreach($bookingSeet as $seer)
<div class="col-md-1">
<div class="seats back seats
@if(in_array($item['name'], $seer['seat']))
activeSeat
@endif"
data-id="{{$key}}">
<div class="special-attributes"></div>
@if(isset($item['name'])){{$item['name']}}@else 11A @endif
<input type="checkbox" name="seat_id[]" id="{{$key}}" value="{{$key}}">
</div>
</div>
@endforeach
@endforeach
</div>
我当前代码的问题是在所有预订表列中获取2个数组,如何在我尝试将ex的复选框复制到刀片时将该值传递给刀片服务器。一辆巴士有50个座位,但现在显示100个座位。可以看到1,1,2,2的座位
一个数组如下:
bookings_id users_id schedules_id buses_id routes_id seat price profile
1 1 6 1 3 1 Null pending
2 1 6 1 3 2 Null booked
3 1 6 1 3 3 null booked
答案 0 :(得分:0)
尝试一下:
$bookingSeat = Bookings::where('schedules_id', $request->schedules_id)->where(function ($q) {
$q->where('profile', 'booked')->orWhere('profile', 'pending');
})->get();
或者这个:
$profileTypes = ['booked', 'pending'];
$bookingSeat = Bookings::where('schedules_id', $request->schedules_id)->whereIn('profile', $profileTypes)->get();
@编辑
这样,如果您的预订表包含所有已注册(1至50)的座位,它将返回您的个人资料针对特定公交车,路线和时间“预订”或“待定”的所有座位。< / p>
$profileTypes = ['booked', 'pending'];
$bookingSeat = Bookings::where('schedules_id', $request->schedules_id)
->whereIn('profile', $profileTypes)
->where('buses_id', $buses_id)
->where('routes_id', $request->route_id)
->get();
答案 1 :(得分:0)
尝试
Bookings::where('schedules_id', $schedules_id)->where('profile', 'booked')->get();
答案 2 :(得分:0)
允许您在任何地方使用数组als。
例如:
$model->where([
['field-one', '=', 'valueOne'],
['field-two', '=', 'valueY']
]);
答案 3 :(得分:0)
如果我正确地理解了这种情况,如果提供了schedules_id并且schedules_id已被预订或待处理,则要检索数据,查询应该是
public class WinformsApartment : IDisposable
{
readonly Thread _thread; // the STA thread
readonly TaskScheduler _taskScheduler; // the STA thread's task scheduler
readonly Task _threadEndTask; // to keep track of the STA thread completion
readonly object _lock = new object();
public TaskScheduler TaskScheduler { get { return _taskScheduler; } }
public Task AsTask { get { return _threadEndTask; } }
/// <summary>MessageLoopApartment constructor</summary>
public WinformsApartment(Func<Form> createForm)
{
var schedulerTcs = new TaskCompletionSource<TaskScheduler>();
var threadEndTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
// start an STA thread and gets a task scheduler
_thread = new Thread(_ =>
{
try
{
// handle Application.Idle just once
// to make sure we're inside the message loop
// and the proper synchronization context has been correctly installed
void onIdle(object s, EventArgs e)
{
Application.Idle -= onIdle;
// make the task scheduler available
schedulerTcs.SetResult(TaskScheduler.FromCurrentSynchronizationContext());
};
Application.Idle += onIdle;
Application.Run(createForm());
threadEndTcs.TrySetResult(true);
}
catch (Exception ex)
{
threadEndTcs.TrySetException(ex);
}
});
async Task waitForThreadEndAsync()
{
// we use TaskCreationOptions.RunContinuationsAsynchronously
// to make sure thread.Join() won't try to join itself
Debug.Assert(Thread.CurrentThread != _thread);
try
{
await threadEndTcs.Task.ConfigureAwait(false);
}
finally
{
_thread.Join();
}
}
_thread.SetApartmentState(ApartmentState.STA);
_thread.IsBackground = true;
_thread.Start();
_taskScheduler = schedulerTcs.Task.Result;
_threadEndTask = waitForThreadEndAsync();
}
// TODO: it's here for debugging leaks
public static readonly WeakReference s_debugTaskRef = new WeakReference(null);
/// <summary>shutdown the STA thread</summary>
public void Dispose()
{
lock (_lock)
{
if (Thread.CurrentThread == _thread)
throw new InvalidOperationException();
if (!_threadEndTask.IsCompleted)
{
// execute Application.ExitThread() on the STA thread
var terminatorTask = Run(() => Application.ExitThread());
s_debugTaskRef.Target = terminatorTask; // TODO: it's here for debugging leaks
_threadEndTask.GetAwaiter().GetResult();
}
}
}
/// <summary>Task.Factory.StartNew wrappers</summary>
public Task Run(Action action, CancellationToken token = default(CancellationToken))
{
return Task.Factory.StartNew(action, token, TaskCreationOptions.None, _taskScheduler);
}
public Task<TResult> Run<TResult>(Func<TResult> action, CancellationToken token = default(CancellationToken))
{
return Task.Factory.StartNew(action, token, TaskCreationOptions.None, _taskScheduler);
}
public Task Run(Func<Task> action, CancellationToken token = default(CancellationToken))
{
return Task.Factory.StartNew(action, token, TaskCreationOptions.None, _taskScheduler).Unwrap();
}
public Task<TResult> Run<TResult>(Func<Task<TResult>> action, CancellationToken token = default(CancellationToken))
{
return Task.Factory.StartNew(action, token, TaskCreationOptions.None, _taskScheduler).Unwrap();
}
}