Laravel 5.8 Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found - laravel

Objective: Changing columns in MySQL with laravel migration, however raises the error below
To change columns in mysql tables using migration requires the installation of the 'doctrine / dbal' dependency. Read the documentation on the link beside [https://laravel.com/docs/5.8/migrations#modifying-columns][1]
Wrong choice for laravel 5.8: $ composer require doctrine/dbal
Problem:
$ php artisan migrate
Migrating: 2021_01_14_031415_my_chage_migrate
Symfony\Component\Debug\Exception\FatalThrowableError : Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found
at ...\vendor\laravel\framework\src\Illuminate\Database\MySqlConnection.php:65
61| * #return \Doctrine\DBAL\Driver\PDOMySql\Driver
62| */
63| protected function getDoctrineDriver()
64| {
> 65| return new DoctrineDriver;
66| }
67|
68| /**
69| * Bind values to their parameters in the given statement.
Exception trace:

Solution:
$ composer remove doctrine/dbal
$ composer require doctrine/dbal:2.*
I hope it helps someone, good luck
;)

dotring/dbal 2.12.1 is the last stable version;
1.composer require doctrine/dbal:2.12.1
2.composer update

Related

Cannot locate class of installed package

I'm writing a laravel package which contains spatie/laravel-sitemap.
I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.
What I did is the usual:
composer require spatie/laravel-sitemap
Then I have created a Console command that have as handle method the following content:
public function handle()
{
SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
$crawler->ignoreRobots();
})
->writeToFile(public_path('sitemap.xml'));
$this->line('<info>Sitemap generated');
}
when I execute the command registered as:
php artisan myapp:sitemap
I get:
Class "Spatie\Sitemap\SitemapGenerator" not found
The reference imported are:
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
I also tried composer update and composer dump-autoload, same problem.
Any help?
register package class in providers array in config/app.php
Spatie\Sitemap\SitemapServiceProvider;
in the bottom of app.php file
i hope it was useful.
you can publish package using this.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config
then
composer dump-autoload
for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

PHP Artisan tinker Class 'XdgBaseDir\Xdg' not found

I encountered and error when running php artisan tinker in my current project. I tried to create a new project using laravel new projectname but the same error occurs when running php artisan tinker.
This is the error that occurs.
````Class 'XdgBaseDir\Xdg' not found
````at C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\ConfigPaths.php:34
````30| * #return string[]
````31| */
````32| public static function getConfigDirs()
````33| {
````> 34| $xdg = new Xdg();
````35|
````36| return self::getDirNames($xdg->getConfigDirs());
````37| }
````38|
````1 C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\ConfigPaths.php:90
````Psy\ConfigPaths::getConfigDirs()
````2 C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\Configuration.php:392
````Psy\ConfigPaths::getConfigFiles()
I badly need help. Thank you so much for anyone that knows the solution.
Finally found the solution. I ask my senior if I can copy his vendor files and a composer update followed. What a relief. Thank you still. Peace out!
(Edit)
If you have a working vendor files, you can copy and paste it to the project files folder where you encounter the said error above. Then do a composer update and your all set.
try this one it worked for me probably you don't have the package installed in the vendor
composer require dnoegel/php-xdg-base-dir
I only had to run composer update

Laravel ER diagram generator getAllModelsFromEachDirectory()

When I try to follow the instruction here (https://github.com/beyondcode/laravel-er-diagram-generator) I get the following error.
Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory() must be of the type array, null given, called in vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php on line 96
at vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:101
97|
98| return $modelsFromDirectories;
99| }
100|
101| protected function getAllModelsFromEachDirectory(array $directories): Collection
102| {
103| return collect($directories)
104| ->map(function ($directory) {
105| return $this->modelFinder->getModelsInDirectory($directory)->all();
Exception trace:
1 BeyondCode\ErdGenerator\GenerateDiagramCommand::getAllModelsFromEachDirectory()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:96
2 BeyondCode\ErdGenerator\GenerateDiagramCommand::getModelsThatShouldBeInspected()
vendor\beyondcode\laravel-er-diagram-generator\src\GenerateDiagramCommand.php:57
Please use the argument -v to see more details.
I've already opened an issue in the repository.
Screen capture of the error:
Posting for others that may encounter same issue.
Confirm you are using the latest version 1.4.0 of the library
Also if you're using php artisan serve try to stop the server. Run php artisan config:cache, and restart the artisan sever.
Note that the reason why you might need to run php artisan config:cache is because Laravel does cache the app's configurations. if you changed or added new configurations you might explicitly need to clear the configuration cache so that Laravel can cache the new configurations.
If no solution yet. Try this
php artisan vendor:publish --provider=BeyondCode\\ErdGenerator\\ErdGeneratorServiceProvider.
Then repeat step 2.

Changing column in Laravel migration causes exception: Changing columns for table requires Doctrine DBAL

I'm trying to change the max length of one of my columns in table reserves in one migration. The code looks like this:
public function up()
{
//
Schema::table('reserves', function($table){
$table->string("mobile", 11)->change();
});
}
But when running the migration via artisan, it throws an exception and says:
[RuntimeException] Changing columns for table "reserves" requires
Doctrine DBAL; install "doctrine/dbal".
What is the problem and how can I solve it?
The problem was solved by executing the following command on the root directory of the framework:
composer require doctrine/dbal
add to composer.json
"require": {
...
"doctrine/dbal": "*"
},
run "composer update" command
or if you can't install the library then:
DB::statement('ALTER TABLE `reserves` MODIFY mobile varchar(11)');

laravel PackageServiceProvider not found; moving from workbench to vendor

This is basically a problem of moving a laravel package from workbench to vendor, but the solutions in other threads have not worked in this case:
I have a package iateadonut/signup.
I created a fresh laravel installation (laravel_test), and, just for testing sake, I put iateadonut/signup in laravel_test/workbench/.
I put Iateadonut\Signup\SignupServiceProvider, in the 'providers' array in app.php.
I then run:
/laravel_test> php artisan dump-autoload
and get:
Generating optimized class loader
Running for workbench [iateadonut/signup]...
My package is successfully installed.
On a fresh installation of laravel (laravel_test), I then put iateadonut/signup in larael_test/vendor.
I put Iateadonut\Signup\SignupServiceProvider, in the 'providers' array in app.php.
I then run:
/laravel_test> php artisan dump-autoload
and get:
PHP Fatal error: Class 'Iateadonut\Signup\SignupServiceProvider' not found in /var/www/html/laravel_test/bootstrap/compiled.php on line 4214
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Iateadonut\Signup\SignupServiceProvider' not found","file":"/var/www/html/laravel_test/bootstrap/compiled.php","line":4214}}
Any idea what could be wrong?
Here is a more google friendly version in case someone else is looking for this:
PHP Fatal error: Class 'Vendor\Package\PackageServiceProvider' not found in /var/www/html/laravel/bootstrap/compiled.php on line 4214
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Vender\Package\PackageServiceProvider' not found","file":"/var/www/html/laravel/bootstrap/compiled.php","line":4214}}
Try to remove the the bootstrap/compiled.php file and try your composer dumpautoload again

Resources