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
Related
I have a problem when declaring autoload in laravel,
i have been using laravel 8 and php 7.4.3 this is the problem
After i get another request, the laravel runner always closing and give me this error
To solve this error, i've always do the
php artisan key:generate
or do another thing like restarting the laravel after dump autoload
composer dump-autoload
php artisan serve
But the problem just solve for one time, and it will be error again until i dump the composer again
How can i solve this?
In your composer.json file you should have the following line
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
And in you artisan file you should have the following
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
The composer.json code should autoload any content coming from the App directory, while the require /vendor/autoloader will load vendor content into your project. Also you must have app.php inside of the bootstrap directory to allow the app to use the Kernal corrently. Hope this helps!
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 am using Amazon LightSail and the CodeIgniter framework. Trying to install PhpSpreadsheet - https://phpspreadsheet.readthedocs.io/en/latest/#installation using
composer require phpoffice/phpspreadsheet
However I then am greeted with
[RuntimeException]
require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead.
I did the usual Googling but couldn't find anything specific.
When I run
composer.phar show
I get the error from above.
You must have mikey179/vfsStream in your composer.json in require-dev section (as the problem is for require-dev and you are trying to do normal require).
Simply change the name of package to all lowercase characters.
Just replace mikey179/vfsStream with mikey179/vfsstream
Make this "mikey179/vfsStream" package name to lowercase.
"mikey179/vfsStream" replace this to "mikey179/vfsstream"
In your composer.json file look for mikey179/vfsStream and lowercase all its characters and make it mikey179/vfsstream
"require-dev": {
"mikey179/vfsstream": "1.1.*",
"phpunit/phpunit": "4.* || 5.*"
}
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.
When I try php artisan serve command at my terminal it gives below error.Can any body help me to fix this issue?
ErrorException
The use statement with non-compound name 'App' has no effect
remove
use App;
from your route.php file, it will work for sure. Thanks.
I hereby post the answer for my own question as I found answer for this and hope this may helpful others in future.
Before : I just used 'use App' only at routes.php
Now : When use 'use App\Http\Controllers' problem solved.
Probably you add 'use App;' in some of your Laravel files, and artisan is parsing the line as an error.
To know which line/file is the error, go to the log file (storage/logs/) and check it out. Then remove that line from the file.