mardi 19 janvier 2016

Laravel 5.2 -> Validation Errors not appearing

I am trying to get validation errors to show up in Laravel.

I have a UserController set up like so:

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;
//Use Request;
Use Flash;
Use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    public function showProfile($id)
    {
        return view('user.profile', ['user' => User::findOrFail($id)]);
    }

    public function store(Request $request) {
        $this->validate($request, [
            'email' => 'required|unique:users|email|max:255',
        ]);

        if($this) {

        $input = Request::all();

        User::create($input);

        return redirect('/');

        }
        else {

            return redirect('/')->withErrors($validator);
        }
    }
}

In my view (layout.blade.php), I have included:

@if (count($errors) > 0)
@foreach ($errors->all() as $error)
   {{!! $errors !!}}
@endforeach
@endif

To account for the route, I have:

Route::group(['middleware' => ['web']], function () {
    Route::get('/', function (){
        return view('home');
    });
});

Unfortunately, when I enter "bad" data that shouldn't be verified, I am not seeing any error (but it is not being stored in the db, so there's that).

One other note, when the blade template is rendered, I am seeing an extra "}" bracket, which I'm not sure why that is there.

Thanks for any help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire