2 years ago

Error messages are not shown after validation

Posted 2 years ago by najmulcse

I want to show error messages after validating of a form . But its not showing the error message when it redirected into previous page . Important point is noted that form validation is working but error message is not shown .

I'm printed for errors checking by {{print_r($errors)}} in my form and its show the following message :Illuminate\Support\ViewErrorBag Object ( [bags:protected] => Array ( ) ) 1

It is assure that the validation is worked properly . When i submitted my form without any values it's not going to other page , it redirected to current page .

#Here i posted my form in a controller method

public function storeLecture(Request $request ){

          'lecture_title'  => 'required ',
          'body'           => 'required',
          'file'           => 'required'
     $v= Validator::make($request->all(),$rules);
             return dd($v);
             //return redirect()->back()->withErrors($v)
      else {
             return  "Ok";
     $file= $request->file('file');
     $user_id = Auth::user()->id;
      'group_id'  => $gid ,
      'user_id'   => $user_id , 
      'title'     => $request->lecture_title ,
      'body'      => $request->body,
      'type'      => 'L'

        $file_store=Content::create(['post_id' => $post_id ,'content' =>$content ]);

      return redirect()->route('allLectures',$gid);  


#my form blade file

<form action="{{route('storeLecture')}}" method="POST" enctype="multipart/form-data">
                                      {{ csrf_field() }}                                                             
                                @foreach($errors as $error)
                                            <input type="hidden" name="gid" value="{{$group->id}}" >
                                      <div class="form-group ">     
                                           <label class="control-label">Lecture Title</label>
                                           <input type="text" name="lecture_title" class="form-control" placeholder="Lecture Title" value="{{old('lecture_title')}}">  
                                     <div class="form-group">
                                            <label class="control-label">Body</label>
                                            <textarea class="form-control" name="body" rows="5" placeholder="Write here...">{{ old('body') }}</textarea>
                                     <div class="form-group">
                                           <label class="control-label">File</label>
                                             <input type="file" name="file" class="form-control" accept=".doc,.ppt,.pdf,.jpeg,.png,.jpg," value="{{ old('file') }}">     
                                     <div class="form-group">

                                          <button type="submit" class="btn btn-sm btn-success pull-right">Upload lecture</button>   

#routes are

Route::get('group/{gid}/allLectures',['as' => 'allLectures' , 'uses' => '[email protected]']);
    Route::get('group/{gid}/createLecture',['as' => 'createLecture','uses' => '[email protected]']);
    Route::post('group/Lecture/store',['as' => 'storeLecture','uses' => '[email protected]']);

When i check the return value for showing all validation by dd($v) its catch the validation but when it redirected to return redirect()->back()->withErrors($v) ->withInput();

no error messages are showing in my form .

Please help me to solve this problem .

Please sign in or create an account to participate in this conversation.