I developed a package for an api in laravel.7.x. That api is delivered as an package for laravel. Now I want to upgrade it to laravel 8. Unfortunately I cannot get the seeders to work.
all package Seeders should executed after the
php artisan migrate:fresh --seed
command.
Appearantly the Seeder classes are not found. for Example Target class [PostSeeder] does not exist.
But it does exist, it's even in the same namespace.
Now I'm trying to start in with a DatabaseSeeder and this one IS found. But from there the other Seeders can't be triggered.
Does anyone has an Idea what can be tried or has a hint or code snippet for this problem?
Many thanks in advance.
alright, the issue is solved.
Use the new way of including factories in laravel 8 i.e Models have this new function:
use Acme\YourPackage\Database\Factories\PostFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
protected static function newFactory()
{
return PostFactory::new();
}
and make sure to call it like:
enter $this->call('Acme\YourPackage\Database\Seeders\PostSeeder');
after that make your sure your namespace and class paths are set correctly.
Symfony version 4.1.
Problem: when I use dd I see only a blank page. body tag does not contain anything. Doing I little dubugging I found that there are different types of debugging output: cli, html, server. And in my case var_dumper.server_dumper service was used as a debugger class. I do not know symfony so good to make some further steps. I guessed that there is service config file where I can pass html_dumper. But I did not find any related files. Symfony docs also show nothing about the configuration. Strange, but google also does not show any relevant results.
Want to add that I installed symfony 4.1 when it was not stable and then I usage of dd/dump gave the same result. But I have run composer update recently and now I should have a fresh symfony version. For long time I used xdebug but sometimes it is much easier to dump a var.
Update:
My code:
namespace App\Controller\SuperAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends Controller
{
/**
* #Route("/", name="home")
* #return Response
*/
public function index()
{
dd(1);
return $this->render('super-admin/home/index.html.twig');
}
}
Update: Just verified that Symfony 4.1.1 has fixed this problem. dd now works as expected out of the box.
Some of this is discussed here: https://symfony.com/blog/new-in-symfony-4-1-vardumper-server
Basically, out of the box, Symfony 4.1 has:
# config/packages/dev/debug.yaml
debug:
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser.
# See the "server:dump" command to start a new server.
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"
The intent (I think) is to intercept debug strings and print them to a console using:
bin/console server:dump
So dd(1); will result in an output in the console as well as a blank web page in the browser. Not entirely sure the Symfony folks intended this to be the default behavior or not.
If you want dd(1) to appear in your html page then change the destination to null.
# config/packages/dev/debug.yaml
debug:
dump_destination: null
In any case, dump() continues to work as expected.
Look like this was in fact a bug: https://github.com/symfony/symfony/issues/27622
Should be fixed in the next 4.1.x release.
Example:
namespace MyApp\Api;
use Mautic\Auth\AuthInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* Base API class
*/
class Api implements LoggerAwareInterface
{
//do Api stuff here
If I upload this to my hosting, I am getting "Class Not found" exception. But i I do simple update:
namespace MyApp\Api;
use Mautic\Auth\AuthInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* Base API class
*/
require_once('Psr/Log/LoggerAwareInterface.php');
require_once('Psr/Log/LoggerInterface.php');
require_once('Psr/Log/NullLogger.php');
class Api implements LoggerAwareInterface
{
//do stuff
Adding keywords require_once solves the problem and it seems that everything is usable.
Now, some of the packages I use in my PHP projects are done by someone else. So I hate the idea of changing files of someone else. Now, what should I check or change on my hosting?
Basic info of my hosting:
-- Webserver Configuration
PHP Version: 5.3.29
MySQL Version: 5.5.5
Webserver Info: Apache
Whad do I have to change on my hosting so the files work on themselves without need to add require keywords?
EDIT I am still bit newbie in PHP programming, so I am using only Notepad++ to develop and usual FTP tool to upload files on my hosting
I am having some issue integrating mongodb with Symfony (version 2.5.0-DEV) using the doctrine mongodb cookbook on http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html.
Everything is okay up to the 'Persisting Objects to MongoDB' stage. When I add the line "$dm->persist($script);", nothing happens to my remote database and I get the error message:
ClassNotFoundException: Attempted to load class "Mongo" from the global namespace in /var/www/Symfony/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Connection.php line 283. Did you forget a use statement for this class?
But without the persist line, the script parses without errors (but nothing happens at the remote database).
Is this particular to my Symfony version (2.5.0) and is there a workaround? I have pasted my entire script below including the use statements. Any help would be appreciated :).
namespace Atlas\MpBundle\Controller;
use Atlas\MpBundle\Document\Scripts;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class UserjsonController extends Controller
{
public function showuserjsonAction()
{
$script = new Scripts();
$script->setName('kingstest');
$script->setDescription('just a desc test');
$script->setGroup('SMS');
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($script);
$dm->flush();
return new Response('Created New Document in scripts with script id '.$script->getId());
}
}
Thanks guys. Works now.
the extension mongo.so has to be loaded in php.ini and I edited the wrong php.ini file. Added extension=mongo.so to php.ini located in /etc/php5/apache2/ and now it works :)
Hopefully this can help someone in the future.
I'm using PHP 5.4, and have a PSR-0 class structure similar to the following.
A\Library\Session.php:
namespace A\Library;
class Session { ... }
My\Application\Session.php:
namespace My\Application;
class Session { ... }
My\Application\Facebook.php:
namespace My\Application;
use A\Library\Session;
class Facebook { ... }
When I try to run the application, I get the following error:
Cannot use A\Library\Session as Session because the name is already in use in My\Application\Facebook.php
Even though it's not, at least not in this file. The Facebook.php file declares only the Facebook class, and imports exactly one Session class, the A\Library one.
The only problem I can see is that another Session class exists in the same namespace as the Facebook class, but as it was never imported in the Facebook.php file, I thought it did not matter at all.
Am I wrong (in that case please point to the relevant documentation), or is this a bug?
There is a bug confirmed in PHP that may affect the behavior you see. It is supposed to fatal error, but with opcache enabled, it may still execute flawlessly.
https://bugs.php.net/bug.php?id=66773
If it still concerns you, please vote for the bug.
No, this is not a bug. As mentioned in Using namespaces: Aliasing/Importing
use A\Library\Session;
is the same as:
use A\Library\Session as Session;
So try using something like:
use A\Library\Session as AnotherSessionClassName;
The only problem I can see is that another Session class exists in the
same namespace as the Facebook class, but as it was never imported in
the Facebook.php file, I thought it did not matter at all.
Yes, it does matter. This is why you don't need to "import" classes from the same namespace. If you have conflicting names from different namespaces, you need to alias the class.
namespace My\Application;
use A\Library\Session as ASession; // choose a proper alias name here
class Facebook { ... }
I've read the thread about the issue, but I tested on many PHP versions (php 5.5, 5.6, 7.*, x32, x64, vc11, vc14, vc5). I'm using Laravel with Laragon. But, when I build up the server with php artisan serve (and open the server at http://localhost:8000) I have the problem of "the namespace that some Class was already used" and stuff.
I tested with and without opcache extension and nothing works, then I tested the virtual domain that Laragon provides and... voila, the error just disappeared and now I can work OK. I don't know what was happening, my namespaces were OK, I had an alias but the same code works in many machine without problem (AWS, local, prod, dev, etc) but only in my machine I had the problem just as I described it.
So, if someone is working with Laravel (5.1) and is having this issue, try the virtual host of Laragon.