对于id,我需要返回id的值。上面的图片不起作用。请有人帮帮我吗?
这是更新过的。
public function rules()
{
return [
'title' => 'required',
'eventDate' => 'required|date|after:yesterday',
];
}
public function messages(){
return [
'title.required' => 'Title is required.',
'eventDate.after' => 'Event Date is passed.',
'eventDate.required' => 'Event Date is required.',
];
}
public function response(array $errors)
{
return $this->redirector->back()
->withInput($this->except($this->dontFlash))
->withErrors($errors)
->with('id', $this->get('id'));
}
控制器
public function edit(Requests\EventRequest1 $request){
$date=$_POST['eventDate'];
$title=$_POST['title'];
$id=$_POST['id'];
$events=EventCal::findOrFail($id);
$events->update($request->all());
DB::table('event_cals')
->where('id',$id)
->update(['title' => $title,'eventDate' => $date]);
return redirect('/dcalendar');
}
视图
@foreach($events as $evnts)
{!! Form::open(array('url'=>'ecalendar','method'=>'POST')) !!}
<table >
<th>Title</th>
<th>Event Date</th>
<tr>
<td><input type="text" name="title" value={!!$evnts->title !!}> </td>
<td><input type="date" name="eventDate" value={!!$evnts->eventDate !!}> </td>
<td><input type="text" name="id" value={!!$evnts->id !!}> </td><br>
<td> <a href="dcalendar/{!!$evnts->eventDate !!}/{!!$evnts->title !!}"><input type="button" name="delete" value="Delete"/> </a></td><br>
<td> <input type="submit" name="edit" value="edit"/> </td><br>
@if($errors->has('title'))
<td><ul class="alert alert-danger" style="width: 250px;height: 40px"> {{$errors->first('title')}} </ul></td>
@endif
@if($errors->has('eventDate'))
<td><ul class="alert alert-danger" style="width: 250px;height: 40px"> {{$id}}</ul></td>
@endif
</tr>
<hr>
</table>
{!! Form::close() !!}
@endforeach
表单值将从db检索值。当我更新值时,应该会出现从请求类中出现的错误消息。对于{{$ id}},我需要id的值。
答案 0 :(得分:0)
在Class的顶部,只需输入,您的请求就可以。
Use Request;
如果您有任何错误,请告知我们,还提供完整的FormRequest文件代码