maki1234's avatar

Lumen Issue with Validator Class

<?php

namespace App\Http\Controllers;

use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FormController extends Controller {
    /**
     * Get user login.
     * 
     * @return Response
     */
    public function get() {
        return view('FormView', ['path' => url('form')]);
    }
    /**
     * Validate and show input.
     * 
     * @param  Request $request
     * @return Response
     */
    public function show(Request $request) {
                $validator = Validator::make($request->all(), [
            'title' => 'required|unique:posts|max:255',
            'body' => 'required',
        ]);

        if ($validator->fails()) {
            return redirect('post/create')
                        ->withErrors($validator)
                        ->withInput();
        }
    }
}
Fatal error: Class 'Validator' not found in C:\xampp\htdocs\project\app\Http\Controllers\FormController.php on line 25

Where the problem is?

0 likes
2 replies
jgodish's avatar
jgodish
Best Answer
Level 6

In bootstrapp/app do you have the withFacades commented out? I believe that would cause this type of error.

$app->withFacades();
maki1234's avatar

Oh my friend! I have only one question. Why the documentation doesn't write about this?

Please or to participate in this conversation.