Call to undefined method Illuminate\Foundation\Application::share() - LARAVEL 9 EXCEL - laravel

i want to make export excel using composer require maatwebsite/excel
this is composer.json code
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0.2",
"barryvdh/laravel-dompdf": "^2.0",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7",
"laravel/ui": "^4.0",
"maatwebsite/excel": "*"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"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,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
when i write
php artisan vendor:publish –provider=”Maatwebsite\Excel\ExcelServiceProvider” –tag=config
the error appears as follows:
Call to undefined method Illuminate\Foundation\Application::share()
at vendor/maatwebsite/excel/src/Maatwebsite/Excel/ExcelServiceProvider.php:159
155▕ */
156▕ protected function bindClasses()
157▕ {
158▕ // Bind the format identifier
➜ 159▕ $this->app['excel.identifier'] = $this->app->share(function($app) {
160▕ return new FormatIdentifier($app['files']);
161▕ });
162▕ }
163▕
+8 vendor frames
9 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
I have followed these tips, but still confused about the share() method in the comments all or not? Laravel - Call to undefined method Illuminate\Foundation\Application::share()

Related

Composer error deploying laravel application on elasticbeanstalk

I have a laravel app hosted on elastic beanstalk and it is also connected with code pipeline. When I deployed the application I got this error on ebs panel:
ERROR: During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
I don't know if it is related but when I downloaded the logs I found this:
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Script #php artisan package:discover --ansi handling the post-autoload-dump event
returned with error code 1
Here is my composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
"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"
]
}
}
It seems that you have some typos. The special character "\" must be "\\" for folder separation.
try this composer.json:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app /",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"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"
]
}
}
Now composer must be able to run scripts. Composer install must finish installation or give you clear warning or error about files.
So I just find out what was going on! I tried to increase my instance and then when I downloaded the complete log there were new information:
021/05/25 18:00:11.083949 [INFO] Running command /bin/sh -c composer.phar install --no-ansi --no-interaction
2021/05/25 18:00:18.791014 [INFO]
ParseError
syntax error, unexpected character 0x1D, expecting "]"
at app/Http/Controllers/MailController.php:28
24▕ 'nome' => $request->nome,
25▕ 'email' => $request->email,
26▕ 'assunto' => $request->assunto,
27▕ 'descricao' => $request->descricao,
➜ 28▕ 'local' => $request->localizacao,
29▕ 'pais' => $request->pais
30▕ ]);
31▕
32▕ if($response->status() === 200)
[2m+1 vendor frames [22m
2 [internal]:0
Composer\Autoload\ClassLoader::loadClass("App\Http\Controllers\MailController")
[2m+9 vendor frames [22m
12 routes/web.php:24
Illuminate\Support\Facades\Facade::__callStatic("post")
2021/05/25 18:00:18.791081 [ERROR] An error occurred during execution of command [app-deploy] - [Install composer dependencies]. Stop running the command. Error: installing composer dependencies failed with error: Command /bin/sh -c composer.phar install --no-ansi --no-interaction failed with error exit status 1. Stderr:Do not run Composer as root/super user! See https://getcomposer.org/root for details
I couldn't see those ascii on vscode but when I opened the project with sublime they were there! I guess my instance was running out of memory therefore It wasn't logging out much and when I changed tiers, more information was logged out. I just removed those ascii and now it is working just fine.

Unable to install "laravel/ui" into a Laravel 8 project using composer

What I tried:
composer require laravel/ui
composer require laravel/ui:^3.2
Directly update composer.json and composer update
All of the tries above ended up the error below.
[InvalidArgumentException]
Could not find package laravel/ui.
Did you mean this?
laravel/ui
Versions:
root#e89196703687:/work/backend# php artisan -V
Laravel Framework 8.11.0
root#e89196703687:/work/backend# php -v
PHP 7.4.13 (cli) (built: Dec 11 2020 08:31:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
composer.jsn
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3",
"auth0/login": "^6.1",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.3.6",
"friendsofphp/php-cs-fixer": "^2.16",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"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"
],
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 775 public/"
],
"fix": [
"php-cs-fixer fix"
]
}
}
Any idea?
To install, you must use the following command. Composer will update according to the package version
composer require laravel/ui:*
try this code:
composer require laravel/ui:^3.0

Upgrade Laravel project from 5.5 to latest version 8

I want to Upgrade my Laravel project from (5.5 to 8) what I will do for that.
I didn't found any documents to upgrade from 5.5 to 8 just upgrade from 5.5 to 5.6 or from 7 to 8 maybe must upgrade the project step by step from 5.5 to 5.6 the from 5.6 to 5.7 then .... nutil 8
Thanks
composer.json(Laravel 5.5):
{
"name": "HomFolio",
"description": "Smart Property Investing",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"ext-json": "*",
"barryvdh/laravel-dompdf": "^0.8.1",
"barryvdh/laravel-translation-manager": "dev-master",
"fideloper/proxy": "~3.3",
"intervention/image": "^2.4",
"joedixon/laravel-translation": "^1.1",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"stripe/stripe-php": "^4.7",
"zizaco/entrust": "dev-master"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0",
"xethron/migrations-generator": "^2.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
}
}
composer.json (Laravel 8):
{
"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": "^7.0",
"laravel/tinker": "^2.0"
},
"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"
]
}
}
Looks like upgrades are sequential. As of today, I have a laravel 5.7 project that I have to upgrade to Laravel 8 and this looks like the sequence I need to take.
Even when you opt for the highly recommended Laravel Shift, you have to pay for each upgrade as indicated in the picture below.
.
If you have budget, laravel shift looks like a quick and easy way to go through the upgrade(s)
You have to follow the steps given below:
Copy the your current composer.json file.
Now go here https://github.com/laravel-shift/laravel-8.x/blob/master/composer.json and copy composer.json file and replace with your existing composer.json file.
Again go to https://github.com/laravel-shift/laravel-8.x/blob/master/app/Exceptions/Handler.php and copy the Handler.php file and go to app/exceptions/Handler.php replace Handler.php with your existing file.
Run the command composer update.
Check your old or your copied composer.json file and if packages have been added to it then you can add packages through this command composer require <package name>.
Now, again run composer update command.
You going to have to upgrade iteratively I'm afraid.
If you have the budget, you can use a service like Laravel Shift
to automate the upgrade.
Adding to some missing steps to #Krina Mangukiya
/bootstrap/environment.php :
$dotenv = Dotenv\Dotenv::createImmutable(DIR.'/..');
$dotenv->load();
The report and render methods of your application's
App\Exceptions\Handler class should accept instances of the Throwable
interface instead of Exception instances:
use Throwable;
public function report(Throwable $exception); public function
render($request, Throwable $exception);
This answers have taken from stackoverflow only but would be go to have all issue answers in one place.

laravel error Illuminate\Routing\RouteFileRegistrar::register(): Failed

Hi I have a problem in laravel version 7
When i run Laravel in localhost, every thing is OK but when i run in Cpanel i get this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Illuminate\Routing\RouteFileRegistrar::register(): Failed opening required '????/laravelPortal/routes/Api.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear')
To make sure the files are loaded so i tested other Laravel sample in this location and it was true work also i remove all of routes file but i get Same above Error
Route::group(['prefix' => 'user'], function () {
Route::post('login', 'Api\UserController#login');
Route::post('register', 'Api\UserController#register');
Route::get('getUser/{id}', 'Api\UserController#getUser')->middleware(['auth:api','scopes:admin,user']);
Route::get('getUser', 'Api\UserController#getUser');
Route::get('logout', 'Api\UserController#logout') ->middleware(['auth:api','scope:admin,user']);
Route::get('checkAdmin', 'Api\UserController#checkAdmin')->middleware(['auth:api','scope:admin']);
});
my composer :
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/passport": "7.5.1",
"laravel/tinker": "^1.0",
"morilog/jalali": "3.*",
"shetabit/payment": "^2.1"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.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"
]
}
}
i had the same issue with linux,it was a kind of case sensitive issue from my end,
i corrected the filename and file and that solved my issue
You can try this
Route::prefix('user')->group(function () {Your routes here});

Laravel: Class 'SocialiteProviders\Manager\ServiceProvider' not found

I am getting the following error when I trying to use Socialite with Laravel and extending it with SocialiteProviders. I have tried other solutions but nothing seems to get rid of this error. Does anyone have any suggestions??? Thanks.
ERROR: Class 'SocialiteProviders\Manager\ServiceProvider' not found
File: Composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"arcanedev/log-viewer": "~4.7.0",
"barryvdh/laravel-cors": "^0.11.3",
"beyondcode/laravel-mailbox": "^1.2",
"browner12/helpers": "^2.1",
"chumper/zipper": "^1.0",
"fideloper/proxy": "^4.0",
"intervention/image": "^2.5",
"laravel/framework": "5.8.*",
"laravel/socialite": "^4.3",
"laravel/tinker": "^1.0",
"league/flysystem-sftp": "^1.0",
"phpmailer/phpmailer": "^6.0",
"socialiteproviders/facebook": "^1.0",
"socialiteproviders/generators": "^4.5",
"socialiteproviders/github": "dev-master",
"socialiteproviders/google": "^3.0",
"socialiteproviders/instagram": "^3.0",
"socialiteproviders/linkedin": "^3.1",
"socialiteproviders/manager": "^3.4",
"socialiteproviders/twitter": "^3.0",
"socialiteproviders/vkontakte": "^4.0",
"socialiteproviders/youtube": "^3.0",
"stripe/stripe-php": "^6.40",
"toin0u/geocoder-laravel": "^4.1",
"tymon/jwt-auth": "1.0.*",
"zanysoft/laravel-zip": "^1.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5",
"infyomlabs/laravel-generator": "5.8.x-dev",
"laravelcollective/html": "^5.8.0",
"infyomlabs/adminlte-templates": "5.8.x-dev",
"infyomlabs/swagger-generator": "dev-master",
"appointer/swaggervel": "dev-master",
"doctrine/dbal": "~2.3"
},
"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"
]
}
}
File app.php
'providers' => [
\SocialiteProviders\Manager\ServiceProvider::class,
],
'aliases' => [
'Socialite' => Illuminate\Socialite\Facades\Socialite::class,
],
File: EventServiceProvider.php
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'SocialiteProviders\\Facebook\\FacebookExtendSocialite#handle',
'SocialiteProviders\\GitHub\\GitHubExtendSocialite#handle',
'SocialiteProviders\\Google\\GoogleExtendSocialite#handle',
'SocialiteProviders\\Instagram\\InstagramExtendSocialite#handle',
'SocialiteProviders\\LinkedIn\\LinkedInExtendSocialite#handle',
'SocialiteProviders\\PayPal\\PayPalExtendSocialite#handle',
'SocialiteProviders\\Twitter\\TwitterExtendSocialite#handle',
'SocialiteProviders\\VKontakte\\VKontakteExtendSocialite#handle',
'SocialiteProviders\\YouTube\\YouTubeExtendSocialite#handle',
],
Registered::class => [
SendEmailVerificationNotification::class,
],
];
File: AuthController.php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Socialite;
class AuthController extends Controller
{
...
Newbie issue.... Composer self "Killed". Fixed the issue by adding swap memory before running composer.
UPDATED to include the command I used to add swap and fix the problem.
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

Resources