2 个型号的自动状态

问题描述 投票:0回答:1

我被一个我以前从未想过的问题困住了两天。

简单来说,我管理 3 个模型(摩托车、修订、训练)。

如果摩托车正在修订或训练中,我必须在我的摩托车表格上看到摩托车不可用。

示例:

有关于

10/08/2019
的摩托车
00004
的训练。

enter image description here

在我的表单

Motorbike
中,摩托车
unavailable
的状态已更改。

enter image description here 好吧!

现在,我的问题出在我的表单中

000004

,如果我为摩托车添加修订版

Revision

enter image description here

我的表单中的状态也必须改变

000002。 这里状态没有改变...


enter image description here 在我的控制器摩托车中,我有这个:

Motorbike

但是,我认为我的问题出在我的index.blade 

public function index() { $motorbikes = Motorbike::oldest()->paginate(5); $bikeIdsDown = Revision::where('date_revision_start', "<=" , Carbon::now())->where('date_revision_end', ">=", Carbon::now())->pluck('fk_motorbike')->toArray(); $bikeIdsDown = Training::where('date_sitting', "<=" , Carbon::now())->pluck('fk_motorbike')->toArray(); return view('admin.motorbikes.index', compact('motorbikes', 'bikeIdsDown')) ->with('i', (request()->input('page',1) -1)*5); }

我的数组仅用于模型?

php laravel laravel-5
1个回答
1
投票

@foreach($motorbikes as $motorbike) <tr> <td>{{$motorbike->matriculation }} </td> <td>{{$motorbike->number_motorbike}}</td> <td> @if(in_array($motorbike->id, $bikeIdsDown)) UNAVAILABLE @else Available @endif </td>

您正在使用 $bikeIdsDown 变量来执行两个查询响应。

将 $bikeIdsDown 变量更改为数组以分配新值。

$bikeIdsDown = Revision::where('date_revision_start', "<=" , Carbon::now())->where('date_revision_end', ">=", Carbon::now())->pluck('fk_motorbike')->toArray(); $bikeIdsDown = Training::where('date_sitting', "<=" , Carbon::now())->pluck('fk_motorbike')->toArray();

或者创建一个新数组并像这样合并:

$bikeIdsDown = Revision::where('date_revision_start', "<=" , Carbon::now())->where('date_revision_end', ">=", Carbon::now())->pluck('fk_motorbike')->toArray(); $bikeIdsDown[] = Training::where('date_sitting', "<=" , Carbon::now())->pluck('fk_motorbike')->toArray();

	
© www.soinside.com 2019 - 2024. All rights reserved.