Laravel 5 如何使用请求类在laravel 5中返回值?

Laravel 5 如何使用请求类在laravel 5中返回值?,laravel-5,Laravel 5,对于id,我需要返回id的值。上面的图片不起作用。有人能帮我吗 这是最新的 public function rules() { return [ 'title' => 'required', 'eventDate' => 'required|date|after:yesterday', ]; } public function messages(){ return [ 'title.required' =

对于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($evnts形式的事件)
{!!Form::open(数组('url'=>'ecalendar','method'=>'POST'))
标题
活动日期
标题!!}>
eventDate!!}>
id!!}>


@如果($errors->has('title'))
    {{{$errors->first('title')}
@恩迪夫 @如果($errors->has('eventDate'))
    {{{$id}
@恩迪夫
{!!Form::close()!!} @endforeach

表单值将从db中检索该值。当我更新值时,应该会出现来自请求类的错误消息。对于{$id},我需要id的值。

在类的顶部,只需键入这个,您的请求就可以了

使用请求


如果您有任何错误,请告知我们,并提供完整的FormRequest文件代码

您不能这样做。但是5分钟前我在这里回答了同样的问题,只需使用通过
response()
函数发送的
$id
var即可。但异常显示为未定义的变量id。@if($errors->has('title'))
    {{{{$id}}
@endif当我使用{{$errors->id}而不是{$id}时,它将显示一个[]。但我需要显示值。这里id是DBA中自动递增的列,您是否正在尝试创建表单验证规则?您是说第一张照片?使用请求将导致错误。请求类代码在上面,您得到了什么错误?和
Request::get('id')
是否记录在用户id中?请同时分享您使用
Request
routes
控制器方法以及您的
表单当前有多少个事件?做一件事,而不是循环事件,只是创建一个单一形式的单一事件,并尝试获取该事件的值。在您的请求文件中,尝试通过此
$this->id
获取id,而不是
request::get('id')
。。。。。。。。告诉我一件事,为什么要在foreach循环中编写表单?假设有1000个事件,那么它将创建1000个表单,这毫无意义。2当我在rules方法中放入'id'=>$this->id时,它将在Validator.php第2615行中显示一个异常作为BadMethodCallException:方法[validate119]不存在。这是我需要的身份证
@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  !!}> &nbsp;&nbsp;&nbsp;&nbsp; </td>

            <td><input type="date" name="eventDate" value={!!$evnts->eventDate  !!}> &nbsp;&nbsp;&nbsp;&nbsp;</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