0

I am using Request Validation for validation. but when validation rule becomes fail then i am not getting that message like wrong name is given .

I use Make::Request Method

My Form Request code

namespace xx\xx\xxx\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class InstituteUpdateRequest extends FormRequest
{
/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules($id=0)
{

    return [
        'name'               =>  'required|regex:/^[(a-zA-Z\s\-)]+$/u|min:3|max:80',
        'valid_from'         =>  'date|max:30|nullable',
        'valid_to'           => 'date|nullable',
        'address'            => 'regex:/^[(a-zA-Z.\-,0-9\s)]+$/u|max:150',
        'mobile'             =>   'required', Rule::unique('users')->ignore($id),
        'city'               => 'regex:/^[(a-zA-Z\-\s)]+$/u|max:100',
        'state'              => 'regex:/^[(a-zA-Z\-\s)]+$/u|max:100',
        'pin'                => 'max:6|regex:/^[(0-9)]+$/u',
    ];
}
}

My Controller code

 public function update ( InstituteUpdateRequest  $request )
  {
     DB::transaction(function () use ($request) {
         $this->institute_update = Institute::where('class_code' ,$request->class_code)->update([
                'name'=>$request->name ,
                'valid_from'=>date('Y-m-d',strtotime($request->valid_from)) ,
                'valid_to'=>date('Y-m-d',strtotime($request->valid_to)),
                'mobile'=>$request->mobile,
                'address'=>$request->address,
                'city'=>$request->city,
                'state'=>$request->states,
                'pin'=>$request->pin,
                'logo' => 'abc',

            ]);
         });
    }

   my API Response 


  {"name":"Demo Institute 1BBBB","valid_from":"29-12-2017","valid_to":"20-12-2018","mobile":"9999999991","address":"Kolar","city":"Bhopal","state":"Madhya Pradesh","pin":"835553","logo":"","class_code":"940370037"}

this is my code. In that case if i am passing wrong name Demo Institute 1BBBB. I am not getting error message. only redirect into my plugin page. that image i share here.

please tell me wt is going wrong.

pankaj
  • 1
  • 17
  • 36

1 Answers1

0

I find my Solution by self. Actually i am not try to make request after login. So that it is being redirect to our plugin page. But when i tried it after login then i got proper format of Error Message.

pankaj
  • 1
  • 17
  • 36