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

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',

Related

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';

How to Solve Controller Error in Laravel6?

I am getting AdminController error, and i am unable to solve this. I am using namespace in web files. Please let me know where i am mistaking.
My error is this..
Target class [App\Http\Controllers\Admin\AdminController] does not exist.
Here are my web.php file
Route::namespace('Admin')->prefix('admin')->name('admin.')->middleware('can:manage-users')->group(function(){
Route::resource('/users', 'UsersController',['except'=>['show','create','store']]);
Route::resource('/dashboard', 'AdminController');
Route::resource('blog', 'BlogController');
});
Here are my AdminController.php File..
<?php
namespace App\Http\Controllers;
use App\Admin;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index()
{
return view('admin.index');
}
}
The error caused by namespace :
Route::namespace('Admin')
// Controllers within the `App\Http\Controllers\Admin` namespace
You need to remove namespace or create AdminController, UsersController, and BlogController under Controllers\Admin folder and namespace.

After adding a new directory into controllers, fatal error thrown

I am new to Laravel and after I added a new directory to the controllers viz, Admin, I updated the namespace also updated routes but somehow, I am getting a fatal error exception. Please help me figure out the problem
App->Http->Controllers->Admin
<?php
namespace App\Http\Controllers\Admin;
class AdminController extends Controller
{
public function index()
{
echo "admin controller";
}
}
routes.php
Route::get('/admin', 'Admin\AdminController#index');
snapshot of directory structure
try
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
public function index()
{
echo "admin controller";
}
}
Note the "use" statement. I suspect that Laravel is looking for the Controller class, which this controller extends, but is unable to find it because of that missing statement.

Laravel : Class controller does not exist

I have created a simple controller and define a function. But when i run this it returns an error that controller does not exist.
In my web.php assign a route.
<?php
Route::get('/', function () { return view('front.welcome'); });
Route::get('plan','PlanController#PlanActivity')->name('plan');
On otherside in my controller my code:
<?php
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Http\Request;
class PlanController extends Controller {
public function PlanActivity()
{
dd("hello");
//return view('admin.index');
}
}
This controller created on App\Http\Controllers\Front - on front folder
Error :
ReflectionException (-1)
Class App\Http\Controllers\PlanController does not exist
Add Front part to:
Route::get('plan', 'Front\PlanController#PlanActivity')->name('plan');
Also, change the top of the controller to:
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
And run composer du.
From the docs:
By default, the RouteServiceProvider includes your route files within a namespace group, allowing you to register controller routes without specifying the full App\Http\Controllers namespace prefix. So, you only need to specify the portion of the namespace that comes after the base App\Http\Controllers namespace.
First when defining route, make sure to use the correct path for the controller. the correct is:
Route::get('plan','Front/PlanController#PlanActivity')->name('plan');
Second you have imported Controller Class as BaseController. so you should extends BaseController not Controller:
class PlanController extends BaseController {
public function PlanActivity()
{
dd("hello");
//return view('admin.index');
}
}

Class with model could not be found in Lumen

In my web browser I am getting this error:
FatalErrorException in UserController.php line 18:
Class 'App\Report'
not found
It seems that UserControler.php page cannot find report.php page.
Here is my folder structure:
lumen
-api
--report.php // file where model Report is
---Http
----Controller
------UserController.php // file where i get error
-bootstrap
- ...
Header of UserController.php
namespace App\Http\Controllers;
use Illuminate\Database\Schema\Blueprint;
use App\Report; // it seems here is problem
use App\User; // with user model is same problem
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
class UserController extends Controller {
...
Header of report.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Report extends Model {
...
I am using Apache, Ubuntu, PHP 5.5 with Lumen framework
First of all model file name should be same as your class name here
lumen
-api
--report.php // This should be Report.php
---Http
----Controller
------UserController.php // file where i get error
-bootstrap
- ...
Also your Report.php Model will be under app directory same directory where your User Model resides

Resources