validator class not found laravel code example

Example 1: Class 'App\Http\Controllers\Validator' not found

use Illuminate\Support\Facades\Validator;

Example 2: command not found: laravel

# For mac just run these 2 commands
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >>  ~/.zshrc
source ~/.zshrc

Example 3: error class helper not found laravel

Step 1: Create your Helpers (or other custom class) file and give it a matching
namespace. Write your class and method:

<?php // Code within app\Helpers\Helper.php

namespace App\Helpers;

class Helper
{
    public static function shout(string $string)
    {
        return strtoupper($string);
    }
}
-----------------------------------------

Step 2: Code within config/app.php
  
<?php
    'aliases' => [
     ...
        'Helper' => App\Helpers\Helper::class,
     ...

---------------------------------------------
  
Step 3:
  
<!-- Code where you want to use Helper class -->

{!! Helper::shout('this is how to use autoloading correctly!!') !!}

reference :
  https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5

Example 4: Class 'App\Http\Controllers\Validator' not found

public function store()
    {
        $rules = array(
            'name'    => 'required',
        );

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

        // if the validator fails, redirect back to the form
        if ($validator->fails()) {
            return Redirect::back()
                ->withErrors($validator) // send back all errors to the login form
                ->withInput();

            $input = input::all();

        } else {

            $company                = New Company();
            $company->name          = Input::get('name');
            $company->user_id       = Input::get('user_id');
            $company->country_id    = Input::get('country_id');
            $company->description   = Input::get('description');

            $company->save();

            return Redirect::to('/backend')->withInput()->with('success', Company added.');

        }
    }

Tags:

Php Example