I'm trying to inject the class HotelsTransformer without success with the next code:
UserTransformer
<?php
namespace App\Transformers;
class UserTransformer extends Transformer
{
...
}
HotelsTransformer
<?php
namespace App\Transformers;
class HotelsTransformer extends Transformer
{
...
}
ApiHotelsController
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \App\Hotel;
use \App\Transformers\HotelsTransformer;
class ApiHotelsController extends ApiController
{
protected $HotelsTransformer;
public function __construct(HotelsTransformer $HotelsTransformer)
{
$this->HotelsTransformer = $HotelsTransformer;
dd($this->HotelsTransformer);
}
When I inject UserTransformer, it's all OK, but when I change UserTransformer with HotelsTransformer it throws me this error.
I don't know why is this happening, because I cloned UserTransformer and change its name but same error persists.
Check your following namespace. May be it does not exist or namespace path is not correct
use \App\Transformers\HotelsTransformer;
Try to run composer dumpauto command.
Try running these commands from your terminal (from the root directory of your project)
// use sudo if it asks for the root permission
composer update
composer dump-autoload
php artisan config:clear
Rerun the app/project and try again.
These 2 commands will refresh composer loaded classes and clear the cache to make the project run freshly, hope it helps.!
Ok, I have solved it, the filename was wrong, changed:
app/Transformers/HotelsTranformer.php
to:
app/Transformers/HotelsTranformer.php
1 hour spent on that like a crazy, good job.
Related
After I installed laravel-dusk following the official Laravel documentation and run this command:
php artisan make:component CardComponentTest
Then try to run immediately:
php artisan dusk tests/Browser/Components/CardComponentTest.php
I get this error:
Class 'Tests\Browser\Components\CardComponentTest' could not be found in '/var/www/html/tests/Browser/Components/CardComponentTest.php'.
I tested file and path are correct:
ls -l /var/www/html/tests/Browser/Components/CardComponentTest.php
And it says:
-rw-r--r-- 1 djw djw 6917 Dec 3 11:25 /var/www/html/tests/Browser/Components/CardComponentTest.php
So it is exists and readable.
I checked the namespace in the file:
<?php
namespace Tests\Browser\Components;
It also looks good.
I checked the composer.json and in this I have this section:
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
So the file exists, the namespace is good and the namespace is picked up in the composer.json.
I tried to run composer dump-autoload too. All good.
Any ide what's wrong whit this?
the error:
Class 'Tests\Browser\Components\CardComponentTest' could not be found in '/var/www/html/tests/Browser/Components/CardComponentTest.php'.
indicate you don't have CardComponentTest test case. Because CardComponentTest is not test case but just an component/part of test.
As aless said, component is not a test itself. But if you really want to test CardComponentTest you can replace
use Laravel\Dusk\Component as BaseComponent;
class CardComponentTest extends BaseComponent
to :
use Tests\DuskTestCase;
class CardComponentTest extends DuskTestCase
after you do that you can run php artisan dusk tests/Browser/Components/CardComponentTest.php , You just need to add test method first like. An example:
public function testComponentExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
But create test case in component folder is not best practice. You should create test case like official documentation said. Run dusk:make instead of dusk:component. An example:
php artisan dusk:make SimpleBrowserTest
and now you can run
php artisan dusk tests/Browser/SimpleBrowserTest.php
If you take a look at the documentation, the Component is not a test itself. Hence, you should not name the component "*Test" and you should not try to run the component like a dusk test.
You will use your component in your dusk test as described here:
https://laravel.com/docs/9.x/dusk#using-components
Components are for repeated actions, like selecting a date in a picker, which is then further used in your test case for example in a form or maybe some change in your UX happens that is assertable.
I have created 2 sub folders just to categorise the seeders files. Other files seems to be working but seeder files which are there in sub folders fails.
It works on my local system but fails on server. I even tried composer dump-autoload without success.
Added namespace Database\Seeders; in all seeders files.
When I try to run the below command getting the below error.
php artisan db:seed --class=TagsIndexDeleteSeeder
In Container.php line 832:
Target class [Database\Seeders\TagsIndexDeleteSeeder] does not exist.
In Container.php line 830:
Class Database\Seeders\TagsIndexDeleteSeeder does not exist
Class Database\Seeders\TagsIndexCreateSeeder located in ./database/seeders/TagsEsSeeder/TagsIndexCreateSeeder.php does not comply with psr-4 autoloading standard. Skipping.
Class Database\Seeders\TagsIndexDeleteSeeder located in ./database/seeders/TagsEsSeeder/TagsIndexDeleteSeeder.php does not comply with psr-4 autoloading standard. Skipping.
TagsIndexDeleteSeeder.php
<?php
namespace Database\Seeders\TagsEsSeeder;
use Illuminate\Database\Seeder;
class TagsIndexDeleteSeeder extends Seeder
{
public function run()
{
}
}
The namespace for your files is wrong.
The files inside the folder database/seeders/TagsEsSeeder need to have namespace Database\Seeders\TagsEsSeeder;.
The files inside the folder database/seeders/UserEsSeeder need to have namespace Database\Seeders\UserEsSeeder;.
So as an example for the file TagsIndexCreateSeeder:
<?php
namespace Database\Seeders\TagsEsSeeder;
use Illuminate\Database\Seeder;
class TagsIndexCreateSeeder extends Seeder
{
//...
}
I created a small symfony4 bundle to manage Mysql database backup.
I created a packagist folder to implement it easily.
after install, my package path is:
webDirectory\vendor\fpasquer\symfony-backup-bundle\BackupSymfonyBundle.php
I'm able to use every class from this bundle excepted commands.
This is one command:
<?php
namespace Fpasquer\BackupSymfony\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class BackupExportCommand extends AbstractBackup
{
protected static $defaultName = 'Fpasquer:BackupSymfony:extract';
...
}
When I run it :
php bin/console Fpasquer:BackupSymfony:extract
I get this exception:
There are no commands defined in the "Fpasquer:BackupSymfony" namespace.
I'm sure my bundle is installed correctly because in my app:controller I'm able to use DependencyInjection from this bundle
Do you have any idea what's wrong?
I was trying to incorporate redis to my Laravel app after learning about it.
And since it is not enabled by default, i've added a line at composer.json file with this: "predis/predis": "1.1.1" under the require.
Next thing i did was run composer update from my CLI.
Once that was done i got this post update:
Then I visit my app page and got this error.
So I looked on my app\Http\Controllers\Controller.php since it was the line it was referring into and went to check if this files still exists but it was not there anymore.
app\Http\Controllers\Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests; <-this
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; <-this
use Illuminate\Foundation\Auth\Access\AuthorizesResources; <-this
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
}
EDIT: Solved
#ceejayoz thank for poiting that out. the downgrade was what caused it. change the 5.2.0. to 5.2.39 and did composer update that now it's back. I was not aware of my own laravel version since i was just using homestead and it was the default values on the composer.json file. Thanks again!
I am trying to run a php script form the command line.
sudo vim UpdateLatestIssuesCommand.php
But its giving me the following error:
PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand' not found in /Applications/MAMP/htdocs/imagine-publishing/src/Imagine/CorporateBundle/Command/UpdateLatestIssuesCommand.php on line 12
I cant figure out why I am getting this error because the file its says it cant find is actually there.
Heres my code:
<?php
namespace Imagine\CorporateBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateLatestIssuesCommand extends ContainerAwareCommand
{
You have to run the command like this
php app/console demo:greet Fabien
where, demo:greet is the name of the command, Fabien is the argument
Reason
Because, console component has to bootstrap required resources for you before it runs the command.
FYI: Console Component