我有两个模型Driver
和DriverCar
我需要按模型显示字段值,让我向您展示我的表单标题代码
请注意Driver
与DriverCar
driver_id
{!! Form::model($driver, [
'route'=>['drivers.update', $driver],
'method'=>'PATCH',
'class'=>'form-horizontal'
]) !!}
现在我的表单字段中有
<div class="form-group">
{!! Form::label('name', trans('interface.DriverName'), ['class'=>'col-sm-2 control-label']) !!}
<div class="col-sm-10">
{!! Form::text('name', null, ['class'=>'form-control', 'placeholder'=>trans('interface.DriverName')]) !!}
</div>
</div>
在我更新时成功更新。但DriverCar
字段如果设置为fillable
,则null
字段未获取$driver->driverCar->car_model
字段我必须通过<div class="form-group">
{!! Form::label('car_model', trans('interface.carModel'), ['class'=>'col-sm-2 control-label']) !!}
<div class="col-sm-10">
{!! Form::text('car_model', $driver->driverCar->car_model, ['class'=>'form-control', 'placeholder'=>trans('interface.carModel')]) !!}
</div>
</div>
等关系获取fillable
$driver->driverCar->car_model
有没有办法让它public function update( Request $request, Driver $driver, DriverCar $driverCar ) {
//dd( $driverCar );
$input = $request->all();
$driver->fill( $input )->save();
$driverCar->fill( $input )->save();
return redirect()->route( 'drivers.edit', $driver );
}
而不给它Driver
这样的关系?
第二 这是我的控制器我尝试一次更新两个表
DriverCar
在控制器中我也无法更新两个表,只更新 1
/ \
2 3
/ \
4 5
> tree <- list(1, list(2), list(3, list(4), list(5)))
> data.tree::FromListSimple(tree, nodeName = "1")
levelName
1 1
2 ¦--1
3 °--2
4 ¦--1
5 °--2
但不触及tree[[1]]
任何指南,请
答案 0 :(得分:1)
您未将update
ID传递给public function update( Request $request, Driver $driver)
{
$input = $request->all();
$driver->fill($input)->save();
$driver->driverCar()->first()->fill($input)->save();
return redirect()->route('drivers.edit', $driver);
}
控制器方法,因此请将代码更改为以下内容:
* {
box-sizing: border-box;
}
body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #fff;
}
/* Global */
.container {
width: 100%;
margin: auto;
overflow: hidden;
border: 1px solid red;
text-align: center;
}
button {
background-color: #ff5f49;
border: none;
padding: 15px;
color: #fff;
font-size: 1.2em;
}
/* Navigation */
header {
background-color: #353c42;
min-height: 75px;
text-align: center;
font-size: 1.3em;
}
nav ul li {
display: inline;
padding: 15px;
text-align: center;
}
nav ul li a {
text-decoration: none;
text-transform: uppercase;
color: #fff
}
/* Jumbotron */
#jumbotron {
}
#jumbotron img {
display: block;
width: 60%;
margin: auto;
margin-top: 80px;
}
.button-1 {
width: 20%;
display: inline-block;
margin: 0 auto;
}
/* Clearfix */
.clearfix::after {
content: "";
clear: both;
display: table;
}