dimanche 24 novembre 2019

Laravel 5.4 does not redirect after unsuccessful validation

I am using basic validation in Laravel (5.4) Controller. If USER submits the form with empty field's the validation is unsuccessful but it won't redirect to the page where the request came from and rather gives me a white blank page. If I click back button on the browser window then I can see the standard error messages on the screen that the fields are empty.

I checked the laravel.log and it gives bunch of errors. I have added the headings of the errors below.

And this issue is with every form on the project. Please help me to solve this issue, THANKS in advance.

Routes: web.php

Route::prefix($language)->middleware(['CheckReferer', 'CheckCart'])->group(function() {
    Route::get('/signin', 'Auth\UserLoginController@getSignIn')->name('user.signIn');
    Route::post('/signin', 'Auth\UserLoginController@postSignIn')->name('user.postSignIn');
}

sign-in.blade.php

<form name="form_signup" id="form_signup" action="" method="post">
    <div class="card">
        <div class="card-block">

            <!--Header-->
            <div class="form-header blue-gradient">
                <h3><i class="fa fa-user"></i> </h3>
            </div>

            <!-- Form validation Errors -->
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li></li>
                        @endforeach
                    </ul>
                </div>
            @endif
            <!-- END Form validation Errors -->

            <!--Body-->
            <div class="md-form">
                <i class="fa fa-envelope text-blue-color prefix"></i>
                <input type="text" id="user_email" name="user_email" class="form-control" value="">
                <label for="user_email"></label>
            </div>

            <div class="md-form">
                <i class="fa fa-lock text-blue-color prefix"></i>
                <input type="password" id="user_password" name="user_password" class="form-control" value="">
                <label for="user_password"></label>
            </div>

            <div class="text-center">
                

                <button type="submit" class="btn btn-primary"></button>
            </div>

        </div>
    </div>
</form>

loginController.php

public function postSignIn(CookieJar $cookieJar, Request $request) {

        $this->validate($request, [
            'user_email' => 'email|required',
            'user_password' => 'required|min:3'
        ]);

        if(Auth::guard('web')->attempt(['user_email' => $request->user_email, 'password' => $request->user_password])) {
            // Successful
            $cookieJar->queue(cookie('userID', Auth::id(), 1440));
            return redirect()->route('home');
        }

        return redirect()->back();

}

laravel.log

local.ERROR: ErrorException: Trying to get property 'headers' of non-object in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:156
Stack trace:
.
.
.
local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 72 in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:170
Stack trace:
.
.
.
local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Cookie\Middleware\EncryptCookies::encrypt() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php on line 59 in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:123
Stack trace:
.
.
.
local.ERROR: ErrorException: Trying to get property 'headers' of non-object in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:156
Stack trace:
.
.
.
local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Session\Middleware\StartSession::addCookieToResponse() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 72 in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:170
Stack trace:
.
.
.
local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Cookie\Middleware\EncryptCookies::encrypt() must be an instance of Symfony\Component\HttpFoundation\Response, null given, called in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php on line 59 in /Applications/MAMP/htdocs/project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:123
Stack trace:
.
.
.


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OEDITZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire