Target class [ControllerName] does not exist (BindingResolutionException) - laravel-9

I have searched the solution for this but mostly the found solutions were for Laravel 8
NOTE: I am using Laravel 9 and My other controllers like Auth, Admin, etc. are working fine.
However, when accessing the URL to test the newly created controller throws
Target class [ControllerName] does not exist
I have already tried
composer dumpautoload
but same error
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ChairmanController extends Controller
{
public function showChairmanDashboard()
{
echo 'Hello';
}
}
My web.php
Route::get('chairman/dashboard', [ChairmanController::class, 'showChairmanDashboard'])->name('chairman.dashboard');
Tried to check the route list via artisan sail artisan route:list throws this
I am using:
Windows 10
WSL2 (Ubuntu 20.04)
Docker Desktop
Laravel Sail

So much for all the trouble. It was an oversight.
Solved by adding this line at the top of web.php
use App\Http\Controllers\ChairmanController;

Related

Multiple declaration of class inside of cache on symfony 2.8

I'm working on an old project in symfony 2.8, i can't upgrade to new versions right now.
Every time i clear the cache on the server i'm working on, I have this error :
FatalErrorException in classes.php line 6203:
Error: Cannot redeclare class Psr\Log\LoggerInterface
I see that LoggerInterface is declared twice in the class.php, that's the problem but i don't know why or where it is declared.
namespace Symfony\Component\HttpKernel\Log
{
use Psr\Log\LoggerInterface as PsrLogger;
interface LoggerInterface extends PsrLogger
{
...
}
and
namespace Psr\Log
{
interface LoggerInterface
{
...
}
I found a similar issue on github : Removing the file class.php from the cache folder
It works fine but it's annoying. I'd like really to fix it.
This problem doesn't happen on production server, only in local setup/other servers

Laravel - Imagick not found when a job calls it

When I call a class from a controller that uses Imagick it works just fine.
When I call the same class from a job it cannot find Imagick
using
$image = new \Imagick();
So not a namespace issue.
Any thoughts most welcome.
EDIT:
So this is a Mac/MAMP specific issue. Works on my production server so I am not so concerned. Both have Imagick extension installed. I suspect artisan listen is making php calls using the system version of php. I did check:phpversion() in my script and it is php 7.020 for both the controller and the job that has the issue. I can live with the mystery :)
Laravel Don't have own Imagick Class u can't use it be default if you have own class add on app/config.php aliases if you don't have i suggest use http://image.intervention.io/getting_started/installation for image convert or crop or anything u like

Laravel 5: Why Class 'App\Console\Commands\SSH' not found?

I'm following instructions on
https://laravelcollective.com/docs/5.1/ssh
in order to use SSH to perform SFTP download from a private server.
I've done so far:
$> composer require laravelcollective/remote
added in config app :
'providers' => [
....
Collective\Remote\RemoteServiceProvider::class,
...
]
'aliases' => [
....
'SSH' => Collective\Remote\RemoteFacade::class,
...
]
published it:
$> php artisan vendor:publish --provider="Collective\Remote\RemoteServiceProvider"
Then I also run a composer update
But still in my console command if I test it like:
$contents = SSH::into('production')->getString('/hi.txt');
dd($contents);
I get the error in my question.
When a service provider is defined like above, the class is globally accessible? Or still I need to put the directive use Path/to/Class ?
If so, since the Alias ahas a different name from the real classname, how should I specify the use path directive?
use Collective\Remote\RemoteServiceProvider
or
use Collective\Remote\RemoteServiceProvider
?
What am I missing?... I've tested other preconfigured services that comes with laravel 5.2 fresh install (i.e. Redis) and they seems to be found without any additional use directive in class.....
Thanks
Just use it as global class \SSH and it will work.
$contents = \SSH::into('production')->getString('/hi.txt');
dd($contents);

Fatal error: Class 'PHPUnit_Extensions_Selenium2TestCase' not found in *.php

I am completely new to Seleniu, and am trying to set up PHPUnit with Selenium 2, following this tutorial https://www.youtube.com/watch?v=zva_GETXimI
So far this is what I've done:
Installed PHPUnit using PHAR as instructed here https://phpunit.de/manual/current/en/installation.html
Installed Selenium Server
Upgraded to PHP5.6 (but my Apache is still 2.22 instead of 2.4)
Installed PHPUnit_selenium package using Composer
Created a testLogin.php file:
<?php
class testLogin extends PHPUnit_Extensions_Selenium2TestCase{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/Achievers');
}
}
When I run testLogin.php using 'phpunit testLogin.php' I get an error:
Class 'PHPUnit_Extensions_Selenium2TestCase' not found in /home/osadmin/projects/Sel/testLogin.php on line 5
Since I am just starting out, I have no idea how to fix this. On googling the error, it shows to add this line to my php file:
require_once('PHPUnit/Extensions/Selenium2TestCase.php');
But I'm not sure how I can use this since there is no PHPUnit folder, just a file linked to the PHAR.
Could someone please shed some light on how to fix this issue?
Thanks.
EDIT:
As per Ushakov's suggestion, I tried /path/to/phpunit.phar testLogin.php
But it gives the same error.
If I add this line to the testLogin.php: require_once('/usr/local/bin/phpunit');
and run /path/to/phpunit.phar testLogin.php
I get this:
#!/usr/bin/env php
PHP Notice: Constant __PHPUNIT_PHAR__ already defined in /usr/local/bin/phpunit on line 18
PHP Notice: Constant __PHPUNIT_PHAR_ROOT__ already defined in /usr/local/bin/phpunit on line 19
PHP Fatal error: Cannot redeclare class DeepCopy\DeepCopy in phar:///usr/local/bin/phpunit/myclabs-deep-copy/DeepCopy/DeepCopy.php on line 15
Solved it by adding this line to the PHP file:
require_once 'vendor/autoload.php';
No tutorial I have seen mentions this, but it can be found in github projects
For anyone else coming late to the party - this worked for me:
class testLogin extends \PHPUnit\Extensions\Selenium2TestCase
(Using PHP 7.0.3 and installing Selenium package with Composer ).

Laravel 4 migrations - class not found

This question is now solved - I used the below:
And, problem solved thanks to IRC. I was told to run
php composer.phar dump-autoload
This fixes the problem for me. It's likely related to my strange Composer setup.
I've just started playing with Laravel 4 for a possible future project, having come from Laravel 3. I have started off by creating a new migration, create_blogs_table using artisan:
php artisan migrate:make create_blogs_table --table=blogs --create
This generated the basic migration file structure which I then filled out a little more:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateBlogsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('blogs', function($table)
{
$table->increments('id');
$table->string('title');
$table->text('description')->nullable();
$table->integer('user_id')->unsigned();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('blogs');
}
}
I now try to run this migration using artisan once again:
php artisan migrate --env=local
*note I have a local database connection set up for domains with the .dev extension
Previously this would work just fine (in Laravel 3) but with Illuminate I then receive this error:
PHP Fatal error: Class 'CreateBlogsTable' not found in /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php on line 301
PHP Stack trace:
PHP 1. {main}() /var/www/gamingsite/artisan:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP 3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP 4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP 5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP 6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP 7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP 8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP 9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP 10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP 11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/gamingsite/app/start/../storage/logs/log-2012-12-28.txt" could not be opened: failed to open stream: Permission denied' in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:71
Stack trace:
#0 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(77): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)
#2 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(214): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#3 /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Logger.php(278): Monolog\Logger->addRecord(400, Object(Symfony\Component\HttpKernel\Exception\FatalErrorException), Array)
#4 [internal function]: Monolog\Logger->addError(Object(Symfony\Component\HttpKernel\Exception\FatalErrorExcepti in /var/www/gamingsite/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 71
PHP Stack trace:
PHP 1. {main}() /var/www/gamingsite/artisan:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/gamingsite/artisan:57
PHP 3. Symfony\Component\Console\Application->doRun() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:106
PHP 4. Illuminate\Console\Command->run() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Application.php:193
PHP 5. Symfony\Component\Console\Command\Command->run() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:95
PHP 6. Illuminate\Console\Command->execute() /var/www/gamingsite/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
PHP 7. Illuminate\Database\Console\Migrations\MigrateCommand->fire() /var/www/gamingsite/vendor/illuminate/console/src/Illuminate/Console/Command.php:107
PHP 8. Illuminate\Database\Migrations\Migrator->run() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:69
PHP 9. Illuminate\Database\Migrations\Migrator->runMigrationList() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:75
PHP 10. Illuminate\Database\Migrations\Migrator->runUp() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:106
PHP 11. Illuminate\Database\Migrations\Migrator->resolve() /var/www/gamingsite/vendor/illuminate/database/src/Illuminate/Database/Migrations/Migrator.php:125
I've checked and the database/migrations/ folder is certainly being autoloaded. I have no idea what the cause for this problem may be. Having asked on IRC and googled I'm still completely clueless so hopefully somebody can help me out here.
Thanks in advance!
I had this error on xubuntu and fixed it with sudo composer dump-autoload
In Laravel 4 (illuminate) migration class do not require you to set unsigned method. You can try this.
class CreateBlogsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('blogs', function($table)
{
$table->increments('id');
$table->string('title');
$table->text('description')->nullable();
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('blogs');
}
}
After having the chat with you, I knew two problems, one is that already mentioned above and the other problem is due to the class not been registered into composer autoload. You will have to run manually : php composer.phar dump-autoload
Artisan do the same work:
php artisan dump-autoload
Just a reminder for those who are not familiar with composer.
Update your composer (composer self-update), then run your composer functions.