Question

I am trying to Get Validation Errors on index.blade.php having issues:

  1. When I fill both the fields then it goes well if i just put an Echo or Return in getLogin Controller.
  2. When I just fill one field and it works good if i just put and echo or Return but not giving validation errors, with Validation Errors it only shows, "Something went Wrong"

Code for index.blade.php

<section class="mainWrap">
    <div class="headingfirst"><img src="{{ URL::asset('css/des.png') }}" width="78"></div>
    <div class="sedhead">Hey User!!!! Try to Login</div>
    <div class="againtext">Sign In To Your Account</div>
    <article class="FormContainer">
            @foreach($errors as $error)
            <div class="errors">{{ $error }} </div>
            @endforeach

        <img class="profile-img" src="{{ URL::asset('css/avatar_2x.png')}}">
        {{ Form::open(array('class'=> 'SetMe')) }}

            {{ Form::text('email',null, array('placeholder'=>'Email','class'=>'insi')) }}
            {{ Form::password('password',array('placeholder'=>'Password','class'=>'dnsi')) }}
            {{ Form::submit('Sign In', array('class'=>'SignIn')) }}

        {{ Form::close() }}
    </article>

</section>

Code for AuthController.php

<?php

class AuthController extends Controller{

    public function GetLogin() {


        return View::make('layouts.index');

    }

    public function LogInfo() {

        $rules = array('email' => 'required','password' =>'required');

        $validator = Validator::make(Input::all(),$rules);

        if($validator->fails()){


                return Redirect::route('login')
                    ->withErrors($validator);
        }
        else{

        }

    }

}

Code for Routes.php

Route::get('login', array('uses'=>'AuthController@GetLogin' ));

Route::post('login', array('uses'=>'AuthController@LogInfo'));

even when i put the Auth Code it don't show anything except "Something goes wrong". but while working with just Echos it works properly

Était-ce utile?

La solution

In validation failed statement,

You need to use return Redirect::to('login') instead of return Redirect::route('login').

In index.blade.php, it should be like -

@foreach($errors->all() as $error)
    <div class="errors">{{ $error }} </div>
@endforeach

instead of

@foreach($errors as $error)
    <div class="errors">{{ $error }} </div>
@endforeach

Also here is my suggestion. if you are currently developing an application using laravel, it is the best to enable debug. Open laravel/app/config/app.php and make sure 'debug' => 'true'. It will help you see what is detailed error messages with stack traces.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top