I am new developer on Laravel, now I'm using Laravel version 5.5
I got the problem after used php artisan app:name on my project, I got the problem:
In ProviderRepository.php line 208: Class
'App\Providers\AppServiceProvider' not found
as the captured image below:
As this error, I can not use php artisan commands or composer commands anymore can you guys please help me to solve this problem I am really appreciated for time. Thanks you
Best Regards
Siripong Gaewmaneechot
I would suggest looking in your config files, and the main classes which were generated when you started your laravel project (User class, etc) because they are all set to App\User App..... etc.
So for example, in the image you have in the question, it says it can not find App\AppProviders... - This indicates that somewhere you still have a use statement pointed to App\AppProviders.. but you changed the app name, so it's no longer App. something I do if I made that mistake, is I do a global search in my project files for App\ (you may need to put App\\ in the search because \ is an escape character
So if you did not change the app name immediately after starting the project, some of the paths will not be pointing to the correct directories. Let me know if that makes sense.
The command changes the PSR-4 configuration in composer.json.
Assume it was App before, your composer.json looks like this:
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
After running the command with php artisan app:name Foo, it will look like:
"autoload": {
"psr-4": {
"Foo\\": "app/"
}
},
Therefore the whole namespace has changed and your classes can't be found by the Autoloader. To fix this, you have to either go back to the old name or do a global search and replace to change the namespace from App to Foo.
Related
I'm trying to develop my first package but I already struggle trying to do so.
I've followed 2 tutorials and done everything exactly as described however I'm getting:
Class "Dkul\Admin\AdminServiceProvider" not found.
I also check my config/app.php path are rights, and add composer, json in my custom package with the same namespace but getting not found error and In console give something like
In ProviderRepository.php line 208: Class "Dkul\Admin\AdminServiceProvider" not found.
file structure
custompackage
Dkul
Admin/src/AdminServiceProvider
Main Composer.json
"Dkul\Admin\":"custompackage/Dkul/Admin/src"
Config/app.php
Dkul\Admin\AdminServiceProvider::class
In Laravel composer.json, autoload section you have set path without top folder "app". Please try:
"autoload": {
"psr-4": {
...,
"Dkul\\Admin\\": "app/custompackage/Dkul/Admin/src"
}
},
I have installed laravel packages on staging server and packages working fine. But when i take pull on staging server, it is showing me error that package class not found.
Steps I have followed to resolve issue
I have check in vendor folder as well as in config/app.php, but I got class declaration and package folder is there.
After this when I update composer, my issue get resolved.
Is there any other file which should i look for class defination?
Perform a composer update, then composer dump-autoload.
If the above doesn't solve the problem, change the classmap in your composer.json file such that it contains the project-relative path to your php files:
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"database/seeds/UserTableSeeder.php" //include the file with its path here
]},
and soon after, perform a composer dump-autoload, and it should work now
I am using the FPDI library from JanSlabon for securing PDF file uploads from my laravel app. But I can't execute the code require_once even though I navigated to the file itself. I am getting the error:
Failed opening required '../../vendor/setasign/fpdf/fpdf.php' (include_path='.:/usr/local/Cellar/php/7.3.4/share/php/pear')
My require code is:
require_once('../../vendor/setasign/fpdf/fpdf.php');
require_once('../../vendor/setasign/fpdi/src/autoload.php');
When the libraries are already located in your vendor folder, you should simply make use of the autoload.php file of composer (doesn't laravel uses this by default?).
So just add the dependencies to your composer.json (if not already done):
"require": {
"setasign/fpdf": "^1.8",
"setasign/fpdi": "^2.2",
"setasign/fpdi-protection": "^2.0"
}
Update via composer update and:
<?php
use setasign\FpdiProtection\FpdiProtection;
require_once('vendor/autoload.php');
$pdf = new FpdiProtection();
...
Your relative path ../../ to vendor is probably wrong. To avoid this issue, use the Laravel base_path() helper which will provide an absolute path.
require_once(base_path('vendor/setasign/fpdf/fpdf.php'));
require_once(base_path('vendor/setasign/fpdi/src/autoload.php'));
You can autoload using composer.json. First of all, create a directory called Custom in app directory and copy fpdi directory to app/Custom.
Now in autoload section of your composer.json file, require the file. After requiring the file, your composer.json file's autoload block should look like this if it is a fresh Laravel app:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Custom/fpdi/FPDI_Protection.php"
]
},
After updating your composer.json file, run composer dumpautoload. Now you can utilize the classes in your Laravel controllers or models without requiring the files manually.
While doing tests, I see that this library uses some deprecated methods and so on. You will have to deal with it, i.e. update the code to suite your needs. But I hope that this answer will help you in a way that you will be able to use any other library as well. Do a Google search and find a more modern library if this one's fixes are too broad.
Is there any simple way to create new module in Laravel, if yes then please explain in detail.
Need to create new custom module in Laravel for users, product etc but didnt understand how to proceed with the same.
These packages will not help you if you don't understanding what exactly are you doing. I really recommend you to start with this tutorial, for example.
You should be right to go with
php artisan module:make <module_name>
You can also create multiple modules at once doing this:
php artisan module:make Users Products
this command will create all the resources you need like controller, seed class service provider and scaffold all the routes. If you dont want all this create new module with the following command
php artisan module:make Products --plain
After research found solution on GITHub :
https://github.com/jaiwalker/setup-laravel5-package
This might be better way to create a new package.
If anybody have better solution, then please share.
To install through Composer, by run the following command:
composer require nwidart/laravel-modules
The package will automatically register a service provider and alias.
Optionally, publish the package's configuration file by running:
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
By default the module classes are not loaded automatically. You can autoload your modules using psr-4 (composer.json). For example :
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
Creating a module is simple and straightforward. Run the following command to create a module.
php artisan module:make <module-name>
It is also possible to create multiple modules in one command.
php artisan module:make Blog User Auth
You can refer this open source project to create module https://asgardcms.com/ - A modular multilingual CMS built with Laravel 5.
I'm new to Laravel 5 and trying to understand it bit by bit and at the moment I'm really confused with error messages. MVC is new thing to me.
What I'm trying to do is blog system for my site and I've downloaded package called "Serverfireteam/blog"; https://phppackages.org/p/serverfireteam/blog
It installed just fine, I guess. When I go to http://myhost.com/public/panel/login I get the login screen but when I login it gives me this error:
ErrorException in Application.php line 1119: Unable to detect application namespace. (View: /var/www/html/mpa2/resources/views/vendor/panelViews/dashboard.blade.php)
&&
RuntimeException in Application.php line 1119: Unable to detect application namespace.
Funny thing is it worked before just fine, I could login and make/edit blog posts and I could see them go to mysql-database. Also I was able to see them on site. Then I started to modify view/template files for integrating blog output to my site's own layout.
I've got no idea what gives, I've tried to google for solution but no help. Any ideas what could be wrong?
Okay, I solved it. What I did to solve this:
composer update
gave me following error:
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 9:
"require-dev
---------------------^
Expected: 'STRING' - It appears you have an extra trailing comma
I opened composer.json and there was one extra comma in last line:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
}
Removed the comma so it looked like this:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
}
And problem was gone.
Usually, this means that your composer.json file contains invalid JSON. Usually an extra comma at the end of an array.
Try running this to tell you exactly where the issue is:
composer diagnose
laravel version: 5.8.3
[One more Reason]: default app path in composer.json is modified
the default setup looks like this
"psr-4": {
"App\\": "app/"
},
If its modified to say,
"psr-4": {
"Core\\": "app/Core/"
},
the make commands with artisan wont work, and a few other things
the reason is https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Application.php#L296
app is static in the path, and here is the where the exception is thrown https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Application.php#L1143
This default behavior can be modified in bootstrap/app.php
Here is my solution [reference: https://laracasts.com/discuss/channels/general-discussion/how-i-can-change-laravel-directory-structure?page=1]
Solution:
Core/Application.php
<?php
namespace Core;
use Illuminate\Foundation\Application as IlluminateApplication;
class Application extends IlluminateApplication
{
protected $appPath = __DIR__;
}
bootstap/app.php
$app = new \Core\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
Please Write this Command on the project root
composer diagnose
This Command Will detect the problem
my case I found this
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 1:
3:06 PM 08-Dec-20{
^
Expected one of: 'EOF', '}', ',', ']'
Then I removed
3:06 PM 08-Dec-20
Then I have Created Controller Succesfully.
I Hope The composer diagnose Command Will Detect Your Problem.
What caused this for me was having lines commented with //. The // can be on its own line or at the end of the line. Also having comma at the end can cause this.
Removing the comments solved this. And/or removing the extra ending comma.
The error happens for "composer update", and artisan commands such as "php artisan make:controller TestsController --resource", or "php artisan make:model Test"
you could open composer.json with visual code.
and
it will parse and mark the issue
i have solve this issue like that