私はステータスフィールドを持つ車のテーブルがあり、 "利用可能"と "故障"があります。 私はまた艦隊CRUDを持っています。艦隊を追加すると、「利用可能」状態の車しか表示されません。私は何を追加すべきですか?ここ具体的な値を取得Laravel
は私の艦隊のコントローラのコードです:
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Models\Fleet;
use App\Models\Car;
use App\Models\Attendance;
use App\Helpers\Enums\FleetStatus;
use App\Models\AttendanceDetail;
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;
use App\Http\Controllers\Base\MasterController;
use Route;
use Illuminate\View\View;
class FleetController extends MasterController
{
protected $detailView = 'fleet.show';
protected $indexView = 'fleet.index';
protected $createView = 'fleet.form';
protected $editView = 'fleet.form';
protected $routeBindModel = 'fleet'; //Route Model Binding name in RouteServiceProvider
protected $redirectPageWhenFormSuccess = 'fleet.index'; //Route Name
protected $title = 'Fleet';
public function save(Request $request, $obj = null) {
if (!$obj) {
$obj = new Fleet;
}
return $this->saveHandler($request, $obj);
}
//Must have this method if need datatable;
public function datatableBuilder($obj = null) {
return Fleet::query();
}
public function makeDatatable($obj) {
return Datatables::of($obj)
->addColumn('action', function ($model) {
return $this->makeActionButtonsForDatatable($model);
})
->editColumn('status', function($model){
return FleetStatus::getString($model->status);
})
->make(true);
}
public function render(View $view, $route = null, $obj = null, $method = 'POST') {
$statusList = FleetStatus::getArray();
$carStatusList = Car::pluck('plate_no', 'id');
$attendanceList = Attendance::pluck('driver_id', 'id');
$workingHourList = Attendance::pluck('working_hours', 'id');
$view->with(compact('statusList', 'carStatusList', 'attendanceList', 'workingHourList'));
return parent::render($view, $route, $obj, $method);
}
}
ここに私の追加フォームのコードは次のとおりです。
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label>Car </label>
{!! Form::select('car_id', $carStatusList, null, array('class' => 'form-control')) !!}
</div>
</div>
@Hiありがとう。 –
IDの代わりにドライバ名を表示する方法を知っていますか? driver_idはattendance-> attendace_detaill-> fleet –
にリンクされています。ドライバモデルの車とドライバの関係を追加する必要があります。public function car(){return $ this-> belongsTo( 'Models \ Car'); }と車のモデルの関数を追加するドライバ(){return $ this-> hasMany( 'Models \ Driver'); }これは、ドライバと車の関係が1対多であることを前提としています。次に、$ car-> driver-> nameに移動します。あなたはどんな関係にもこれをもっと詳しい情報に適用することができますhttps://laravel.com/docs/5.3/eloquent-relationships – Indra