code error when creating controller in laravel - laravel

code error when creating controller in laravel php artisan make:Controller KmsController
RuntimeException
Unable to detect application namespace.
Illuminate\Console\GeneratorCommand::rootNamespace()
and I tried: composer dump-autoload
In JsonFile.php line 340:
"./composer.json" does not contain valid JSON
Parse error on line 65:
...fer-stable": true}{ "require": {
--------------------^
Expected one of: 'EOF', '}', ',', ']'

If your json you posted is exactly like that, your error is at the bottom, see this part:
{
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
} // HERE IS THE ERROR
{
"require": {
"phpoffice/phpspreadsheet": "^1.23"
},
"config": {
"platform": {
"php": "7.3"
}
}
}
You have to move the text inside the require (at the bottom) into the top where you also have require, same for config...
Your JSON should be like this:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"consoletvs/charts": "6.*",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"ladumor/laravel-pwa": "^0.0.3",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"phpoffice/phpspreadsheet": "^1.25",
"phpoffice/phpspreadsheet": "^1.23"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^5.10",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"platform": {
"php": "7.3"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
BUT, you can see you now have the same package, twice, with 2 different versions:
"require": {
"php": "^7.3|^8.0",
"consoletvs/charts": "6.*",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"ladumor/laravel-pwa": "^0.0.3",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"phpoffice/phpspreadsheet": "^1.25",
"phpoffice/phpspreadsheet": "^1.23"
},
You will have to know if phpoffice/phpspreadsheet needs to be ^1.25 or ^1.23. I will assume using 1.25 is fine

Related

Laravel upgrade advice

I have an old project with laravel 5.8;
I've tried to update to 6 & 7 & 8, no luck.
I just want to know where to start from. Right now, all i'm doing is changing versions of different packages...Should i remove any lines or what? What all ways do you upgrade a really old project?
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.1.3",
"aporat/store-receipt-validator": "dev-master",
"barryvdh/laravel-debugbar": "^3.0",
"chumper/zipper": "1.0.x",
"doctrine/cache": "^1.6",
"doctrine/dbal": "^2.5",
"google/apiclient": "^2.0",
"intervention/image": "^2.4",
"laravel/framework": "5.8.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.3.0",
"maatwebsite/excel": "~3.1",
"mariuzzo/laravel-js-localization": "^1.4",
"piwik/device-detector": "^3.9",
"spatie/pdf-to-image": "^1.5",
"spatie/laravel-image-optimizer": "^1.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Weltwoche\\": "app/"
},
"files": [
"app/Helpers/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}

Issue with composer: "Your requirements could not be resolved to an installable set of packages"

When I run composer update I get an error message:
"Your requirements could not be resolved to an installable set of packages".
I uploaded some screenshots of the issue below:
This is what my composer.json file looks like.
Composer.json:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "5.2.*",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.0",
"intervention/image": "2.*",
"laravelcollective/html": "^6.1"
},
"require-dev": {
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
As the error message already tells you: you try to mix different versions of Laravel. laravelcollective/html with the version requirement ^6.1 requires Laravel v6 or v7, and some lines above you require Laravel 5.2. Either upgrade laravel/framework to a later version, or downgrade laravelcollective/html to a version that is compatible

Installing laravolt/avatar I got error method Laravolt\Avatar\Facade::isDeferred

I tried to install /laravolt/avatar pluging in my laravel 6 app and got error while installing:
$ composer require laravolt/avatar
Using version ^3.0 for laravolt/avatar
In ProviderRepository.php line 149:
...
Call to undefined method Laravolt\Avatar\Facade::isDeferred()
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
At https://github.com/laravolt/avatar site I see last updates 5 days ago and I suppose it is not absolute ?
File composer.json of my project :
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2",
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.2",
"laravel/helpers": "^1.1",
"laravel/passport": "^8.1",
"laravel/tinker": "^2.0",
"laravolt/avatar": "^3.0"
},
"require-dev": {
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"laravel/ui": "^1.1",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^8.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
Why I have error and how to fix it ?
I searched in net and did not find how to fix it ?
Thanks!

In Laravel Framework 5.7.3 error on linksOnEachSide method

I moved my laravel application to 5.7 :
$ php artisan --version
Laravel Framework 5.7.3
but trying to use new pagination method linksOnEachSide what I found in docs:
$homepage_quizzes_per_page= 2;
$activeQuizVotes= Vote::getByStatus('A')->
getByIsHomepage(true)->
getByIsQuiz(true)->
orderBy('ordering','desc')->
orderBy('created_at','desc')->
leftJoin(\DB::raw('vote_categories as vc '), \DB::raw('vc.id'), '=', \DB::raw('votes.vote_category_id'))->
select(\DB::raw(" votes.*, vc.name as vote_category_name, vc.slug as vote_category_slug"))->
paginate($homepage_quizzes_per_page)->
linksOnEachSide( (int)($homepage_quizzes_per_page/2) );
I got error :
Method Illuminate\Database\Eloquent\Collection::linksOnEachSide does not exist.
If in code above to comment last line with linksOnEachSide - it works ok and I have valid pagination.
My composer.json has :
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.1.3",
"cviebrock/eloquent-sluggable": "^4.5",
"davejamesmiller/laravel-breadcrumbs": "5.x",
"doctrine/dbal": "^2.8",
"fideloper/proxy": "^4.0",
"intervention/image": "^2.4",
"itsgoingd/clockwork": "^3.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"laravelcollective/html": "^5.4.0",
"proengsoft/laravel-jsvalidation": ">2.2.0",
"rap2hpoutre/laravel-log-viewer": "^0.19.1",
"snowfire/beautymail": "dev-master",
"themsaid/laravel-mail-preview": "^2.0",
"wboyz/laravel-enum": "^0.2.1",
"yajra/laravel-datatables-oracle": "^8.7"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.1",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
],
"post-update-cmd": [
"php artisan vendor:publish --provider=\"Proengsoft\\JsValidation\\JsValidationServiceProvider\" --tag=public --force"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Why error and how to fix it ? Some invalid options ? Or I have to update some more libs apart "laravel/framework": "5.7.*" ?
Thanks!
The method has been renamed to onEachSide().

laravel autoload classmap class not found

I have some helpers in my factories directory (database\factories\FactoryHelpers.php)
<?php
class FactoryHelpers
{
...
}
Now I try to use it in my tests, and get class FactoryHelpers not found
I thought that putting
"classmap": [
"database/factories"
],
In my composer file should be enough to make the FactoryHelpers class available globally.
EDIT:
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"barryvdh/laravel-cors": "^0.9.3",
"fideloper/proxy": "~3.3",
"guzzlehttp/guzzle": "^6.0",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"webpatser/laravel-uuid": "^3.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "v2.4.1",
"codeception/codeception": "^2.3",
"doctrine/dbal": "^2.6",
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"krlove/eloquent-model-generator": "^1.2",
"mockery/mockery": "0.9.*",
"mpociot/laravel-test-factory-helper": "^0.5.0",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}

Resources