2015-11-03 85 views
0

我想填寫我的表單,當用戶點擊編輯 事情是我的表單沒有填充。 我已檢查傳遞給視圖的$錦標賽變量是否包含正確的信息。 我可以將默認值設置爲$ tournament->字段,但我在laracast中看到它不是必需的,有一種更簡單的方法可以做到這一點。{!! Form :: model不工作在laravel 5

這裏是我的控制器 類TournamentController擴展控制器 {

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" => ["[email protected]", $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

我根據對Form Model Binding的Laravel集體文檔認爲,你需要提供一個資源路線(而不是動作)

echo Form::model($user, array('route' => array('user.update', $user->id))) 
+0

好的,我改了它,但仍然沒有填寫我的表格 –

+0

('name',\ Carbon \ Carbon :: now()); 而該表::輸入(「日期」,等等等等 – Leo

+0

ErrorException在Macroable.php線81:方法日期不存在 –

0

試試這個在您的編輯方法:

return view('tournaments.edit', ['tournament'=>$this->tournament, 'places'=>$places ]); 

return view('tournaments.edit', compact('tournament'), compact('places'));