Solving Uncaught ReflectionException: Class log does not exist in C:\......\Container.php: - laravel

I am experiencing an unexpected Reflection Exception error that class log does not exist. I am currently using Laravel 5.2. The addition of use log amongst namespaces into my controller hasn't solved this.
Fatal error: Uncaught ReflectionException: Class log does not exist in C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:741
Stack trace:
#0 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(741): ReflectionClass->__construct('log')
#1 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(631): Illuminate\Container\Container->build('log', Array)
#2 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(674): Illuminate\Container\Container->make('log', Array)
#3 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(842): Illuminate\Foundation\Application->make('log')
#4 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php(775): Illuminate\Conta in C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 741
controller.php
<?php
namespace App\Http\Controllers;
use Log;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class Controller extends BaseController
{
use AuthorizesRequests,AuthorizesResources, DispatchesJobs, ValidatesRequests;
}
routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
Route::get('/', function () {
return view('welcome');
});

Check for spaces in your .env or config files as suggested here
https://laracasts.com/discuss/channels/general-discussion/class-log-does-not-exist?page=2
enclose it with double quotes if any

Related

Laravel Target class [App\Http\Controllers\HomeController] does not exist

I was making a small blog site, but got this error. Is there anyone who can help? Currently, my homepage page that I defined in view is not working.
My homepage.blade.php page, by the way, inside the front folder is homepage.blade.
my web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Front\HomeController;
Route::get('/',"HomeController#index");
-----------------------------------------------
here is my controller
<?php
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Front\HomeController;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Category;
class HomeController extends Controller
{
public function index(){
$data['categories']=Category::inRandomOrder()->get();
return view('front.layouts.homepage',$data);
}
}
You have to use like below code
Route::get('/', [HomeController::class, 'index']);
I think you should do like this -
Route::get('/','Front\HomeController#index');
because You have directory like App\Http\Controllers\Front\HomeController.
and you can't call without calling the exact path.
hope, It helps.

I am getting target class does not exist error in laravel 8

The routing process has changed in Laravel version 8. I did as in the internet but it gives an error. Where am I doing wrong?
Route file
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Backend\BackendHomeController;
Route::get('/', function () {
return view('welcome');
});
Route::get('/admin', [BackendHomeController::class, 'index'])->name("index");
Controller file
<?php
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public static function index()
{
return view("backend.index");
}
}
BackendHomeController also like this. Everything seems to be correct, but am I doing something wrong with using?
Error says
target class does not exist error
Class is referenced as BackendHomeController but your file is named HomeController. These should align for autoloading to be working.

error vendor\laravel\framework\src\Illuminate\Container\Container.php:833 in laravel

please help me, I'm learning and using Laravel 8.x . I don't know what is my error in this case.
...
vendor\laravel\framework\src\Illuminate\Container\Container.php:833
...
this is my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index(){
echo'admin';
}
}
and this is my web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/admin','AdminController#index');
Since Laravel 8 default namespace App\Http\Controllers is not registered by default in RouteServiceProvider
So you need to use FQCN for the controller in the routes file other wise you will get the container binding resolution exception as you are getting
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
Route::get('/admin', [AdminController::class, 'index']);
This happens from Laravel 8, since the App\Http\Controllers namespace isn't registered by default. You can register it in the corresponding service provider:
# app/Providers/RouteserviceProvider.php
// Uncomment this line
protected $namespace ='App\\Http\\Controllers';

laravel Log not found in application.php

I want to use Logto log ,it works in controller,but it doesn't work in application(vendor/laravel/framework/src/Illuminate/Foundation/Application.php)
this is my code:
<?php
namespace Illuminate\Foundation;
use Log;
use Closure;
use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\ServiceProvider;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Routing\RoutingServiceProvider;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
class Application extends Container implements ApplicationContract, HttpKernelInterface
{
public function make($abstract, array $parameters = [])
{
$abstract = $this->getAlias($abstract);
if (isset($this->deferredServices[$abstract])) {
$this->loadDeferredProvider($abstract);
}
Log::info('test info '); // 698 line
return parent::make($abstract, $parameters);
}
I catch the error when I up the artisan serve:
php artisan serve
Fatal error: Class 'Log' not found in vendor/laravel/framework/src/Illuminate/Foundation/Application. php on line 698

FatalErrorException in Model.php line 986: Class 'App\Role' not found

My routes.php file is
<?php
use App\models\User;
use App\models\Permission;
use App\models\Role;
Route::get('/roles', function()
{
//code
}
and my role.php file is
<?php
namespace App\models;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
and I found the error like this
FatalErrorException in Model.php line 986: Class 'App\Role' not found
The default Entrust config file looks for models inside the App namespace, not the App\models namespace. You need to publish the config file and update it accordingly:
'role' => 'App\models\Role',

Resources