我在用户点击“修改”时尝试填写表单 事情是我的形式没有填补。 我检查过传递给视图的$ tournament变量是否包含正确的信息。 我可以将默认值设置为$ tournament->字段,但我在laracast中看到它不是必需的,有一种更简单的方法可以做到。
这是我的控制器 class TournamentController扩展Controller {
public function edit($id)
{
$places = Place::lists('name', 'id');
$tournament = Tournament::findOrFail($id);
return view('tournaments.edit', compact('tournament', 'places'));
}
模型
class Tournament extends Model {
protected $table = 'Tournament';
public $timestamps = true;
protected $fillable = [
'name',
'tournamentDate',
'registerDateLimit',
'placeId'
];
protected $dates = ['tournamentDate','registerDateLimit'];
public function geTournamentDateAttribute($date)
{
return $date == "0000-00-00 00:00:00" ? "0000-00-00 00:00:00" : $date;
}
public function getLimitRegisterDateAttribute($date)
{
return $date == "0000-00-00 00:00:00" ? "0000-00-00 00:00:00" : $date;
}
public function setTournamentDateAttribute($date){
$this->attributes['tournamentDate'] = Carbon::createFromFormat('Y-m-d', $date);
}
public function setLimitRegisterDateAttribute($date){
$this->attributes['registerDateLimit'] = Carbon::createFromFormat('Y-m-d', $date);
}
}
查看
edit.blade.php
@extends('app')
@section('content')
<h1>@lang('crud.editModel', ['currentModelName' => $currentModelName])</h1>
<hr/>
{!! Form::model($tournament, ['method'=>"PATCH", "action" => ["TournamentController@update", $tournament->id]]) !!}
@include("tournaments.form", ["submitButton" => "@lang('crud.updateModel', ['currentModelName' => $currentModelName])"])
{!! Form::close()!!}
@include("errors.list")
@stop
form.blade.php
<div class="form-group">
{!! Form::label('name', trans('crud.name')) !!}
{!! Form::text('name', '', ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('tournamentDate', trans('crud.eventDate')) !!}
{!! Form::input('date', 'tournamentDate', \Carbon\Carbon::now()->format('Y-m-d'), ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('limitRegistrationDate', trans('crud.fullLimitDateRegistration')) !!}
{!! Form::input('date', 'limitRegistrationDate', \Carbon\Carbon::now()->format('Y-m-d'), ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('placeId', trans('crud.place')) !!}
{!! Form::select('placeId', $places,null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit($submitButton, ['class' => 'btn btn-primary form-control']) !!}
</div>
任何想法???
答案 0 :(得分:0)
我认为根据Form Model Binding上的Laravel Collective文档,您需要提供资源路径(而非动作)
echo Form::model($user, array('route' => array('user.update', $user->id)))