php - Laravel 5.2 Validation Error not appearing in blade -
i want show validation error in view page while user giving wrong input. it's ok it's not saving in database while user giving wrong input. there no error message in user view page. if find error, please me out.
here controller:
public function saveuser(request $request){ $this->validate($request,[ 'name' => 'required|max:120', 'email' => 'required|email|unique:users', 'phone' => 'required|min:11|numeric', 'course_id'=>'required' ]); $user = new user(); $user->name= $request->input(['name']); $user->email= $request->input(['email']); $user->phone= $request->input(['phone']); $user->date = date('y-m-d'); $user->completed_status = '0'; $user->course_id=$request->input(['course_id']); $user->save(); return redirect('success'); }
here route:
route::group(['middleware' => 'web'], function () { route::get('/', function () { return view('index'); })->name('main'); route::post('/saveuser',[ 'uses' => 'appcontroller@saveuser', 'as'=>'saveuser', ]); });
here blade view page:
@extends('layouts.master') @section('title') create user @endsection @section('content') @include('partials.message-block') <div class="container" > <h3> student register </h3> {!! form::open(array('route' => 'saveuser','class'=>'form-horizontal','method'=>'post')) !!} {!! form::token(); !!} {!! csrf_field() ; !!} <div class="form-group"> <label>name</label> <input type="text" name="name" class="form-control" required placeholder="name"> </div> <div class="form-group"> <label>email</label> <input type="email" name="email" class="form-control" required placeholder="email"> </div> <div class="form-group"> <label>phone number</label> <input type="text" name="phone" class="form-control" required placeholder="phone"> </div> <div class="form-group"> <label for="">class</label> <select class="form-control input-sm" name="course_id" > @foreach($input $row) <option value="{{$row->id}}">{{$row->name}}</option> @endforeach </select> </div> <button type="submit" class="btn btn-default">submit</button> {!! form::close() !!} </div> @endsection
and here error-message block:
@if(count($errors) > 0) <div class="row"> <div class="col-md-4 col-md-offset-4 error"> <ul> @foreach($errors->all() $error) <li>{{$error}}</li> @endforeach </ul> </div> </div> @endif @if(session::has('message')) <div class="row"> <div class="col-md-4 col-md--offset-4 success"> {{session::get('message')}} </div> </div> @endif
try remove web
middleware if you're using 5.2.27 or higher. thing laravel automatically applies web
middleware routes inside routes.php
, if you're trying add manually can errors.
app/providers/routeserviceprovider.php
of 5.2.27 version adds web middleware routes inside routes.php
:
protected function mapwebroutes(router $router) { $router->group([ 'namespace' => $this->namespace, 'middleware' => 'web', ], function ($router) { require app_path('http/routes.php'); }); }
Comments
Post a Comment