I am developing web based project management tool using laravel 5. when I execute it occurred following error.
FatalErrorException in ProjectController.php line 37: Class
'App\Http\Controllers\Project' not found
Make sure you import your Project class with proper use statement, otherwise PHP will look for this class in current namespace.
E.g. if your Project class is in App\Models namespace, add the following at the top of your controller file:
use App\Models\Project;
Related
I have installed a plug-in called tet. I copied tet.so in the plug in folder and included it in php.ini
I have checked phpinfo and says that the plugin is enabled and running.
I have created a php page to test it.
<?php
new tet();
?>
And works perfectly.
However when I try this on my laravel it gives me this error:
FatalThrowableError in mycontroller.php line 16: Class
'App\Http\Controllers\tet' not found
tet is not a controller. Tet is a class created by the php plugin. How do I include this in laravel?
You should try
new \tet();
because you are using it inside a namespace. Inside a namespace any reference to a class is considered as relative to the namespace you are in. With the "\" you can "escape" the namespace and so you can access classes outside.
I need some help with a problem. I'm trying to execute a simple build with tests on Travis-CI, but its error, saying that it could not found Class:
Fatal error: Class 'com\bitshammer\collection\utils\CollectionUtils' not found in /home/travis/build/BitsHammer/CollectionUtils/test/CollectionUtilsTest.php on line 20
Just for your knowledge, it’s my first project using Composer! What I am doing wrong? Do you guys have any idea? Thanks!
Travis-CI page
Project page on GitHub
I believe your namespaces are wrong for the autoloading.
In composer.json, your autoloading maps the namespace com\bitshammer\ to src/.
You currently have the namespace at com\bitshammer\collection\utils which means your file path for this class would instead needs to be src/collection/utils/CollectionUtils.php instead of src/CollectionUtils.php.
Alternatively you could change the namespace for this class to be com\bitshammer instead of com\bitshammer\collection\utils.
I recently decided to develop a new website with drupal 8 (i never used drupal 7 or other version).
I had to create a module and i need a custom class in this module and i create a service to use it. But i've an error, my custom class is not find.
When i had a require of my class in the autoload.php, it's work. So my service is correct but my class is not include in my autoload.
Anyone have a solution for my problem ?
Do you "use" the class? Like that:
use Drupal\your_namespace\yourClass;
Of course your class needs a namespace to make this work.
you need follow PSR4 rule, if your class is defined in module, you should put your class file into the correct folder structure , for example if your class namespace defined as "Drupal\your_module_name\yourClass" , the file folder structure should be: modules\your module name\src\ (your Class file)
I'm sure that the solution to this problem is staring me right in the face, but unfortunately I can't seem to figure it out. I'm trying to add a route to my laravel 5.1 installation, and I'm getting the below error...
ReflectionException in Container.php line 737:
Class App\Http\Controllers\Tools\DashBoardController does not exist
I first edited the routes file to include the below...
(file: app\Http\routes.php)
Route::get('dashboard', 'Tools\DashBoard#index');
Then I created the "Tools" folder and "DashBoardController.php" file, and have it setup to look somewhat like the below...
(file: app\Http\Controllers\Tools\DashBoardController.php)
namespace App\Http\Controllers\Tools\DashBoard;
//...etc...//
class DashBoardController extends Controller { /* ..etc.. */ }
Is this all I have to do? I read that you could run "composer dumpautoload" in the terminal but unfortunately that didn't help.
I'm on a localhost XAMPP install w/PHP7 on Win7, if that's useful. Any help is greatly appreciated!
Your namespace declaration should look like namespace App\Http\Controllers\Tools and should not contain the filename or name of your class. Then you need to change your route to point to the name of your class Route::get('dashboard', 'Tools\DashBoardController#index');.
The way autoloaders and namespaces work in PHP and specifically in Laravel is that the namespace must reflect the directory structure and the class name must match its filename.
If you will have multiple routes using controllers from the same namespace, you will probably benefit from implementing route group namespaces.
I am getting a namespacing issue when trying to extend the Response facade in Laravel 5. I have created a new folder tree under the app directory called Extensions\Facades. In this folder I have a file called AjaxResponse.php which has the following contents:
<?php namespace App\Extensions\Facades;
use Illuminate\Support\Facades\Response;
class AjaxResponse extends Response{
public static function send($code,$body,$http_code=200){
parent::json( array(
'status'=>(string)$code,
'body' =>$body
) )->setStatusCode($http_code)->send();
exit();
}
}
I am registering this as a service provider in config/app.php like I understand I am supposed to:
providers=[
//..normal stuff
'App\Extensions\Facades\AjaxResponse',
]
And this is throwing the normal namespace error of class not found:
FatalErrorException in ProviderRepository.php line 150:
Class 'App\Extensions\Facades\AjaxResponse' not found
Can anyone shed any light on why the class is not found?
Go to project root folder and in the terminal type
composer dump-autoload
Everything should be fine then. When you create a new folder, composer does not know about it, so it can not autoload files from it, even if they are psr-4 namespaced.
EDIT Also you need to declare alias for your facade in config/app.php under aliases array, not the providers one:
'AjaxResponse' => 'App\Extensions\Facades\AjaxResponse',