I'm working with a Laravel 5.2 test site, and I'm using the built-in auth system to handle logins.
I changed the name of the app namespace to myTest using php artisan app:name myTest
However, when I submit the login form I'm still getting an error due to a namespace issue in the auth system:
FatalErrorException in EloquentUserProvider.php line 126:
Class '\App\User' not found
Is there somewhere I need to edit the namespace so that this will work?
EDIT: PSR4 block of composer.json is:
"psr-4": {
"myTest\\": "app/"
}
Yes, I did already composer dump-autoload to try to refresh the namespacing, and the same issue appears.
You need to update your config/auth.php file.
Check under providers -> users -> model.
Adjust that from App\User::class to your class.
Related
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.
I am creating my first package with Laravel 7.
Idea is make login and register process inside it.
Login and Register forms are working,
and process logic work aswell.
When I am calling them from route-file directly Blade form.
But
I have added login and register controller.
After login form send request to logged in,
comes issues:
Issue 1) Trait Illuminate\Foundation\Auth\AuthenticatesUsers
not found.
Tried so far:
added "laravel/ui" to Composer.json inside my package.
---- Edit ---
I found "illuminate/auth" from Github/Laravel/framework/blob/7.x/src/illuminate/Auth/composer.json
namespace is same as error.
installed but still same error.
Q) Do I miss some other package which calls User trait ?
Thanks Mika.
--- EDIT ----
I have been searcing few days to way to do it.
Found https://laracasts.com/discuss/channels/laravel/create-laravel-route-inside-another-composer-packages
But it is for Larave 5.X, is it still valid way to fix this problem ?
If you want to use Laravel's built in authentication, this is how you set it up:
Run
composer require laravel/ui
Then run
php artisan ui:auth
and
php artisan migrate
If you want to use Vue with the UI scaffolding you can run php artisan ui vue --auth instead of php artisan ui:auth.
So I'd recommend to undo what you did (seems like you didn't run through the install steps properly) and then follow the steps above. More info in the official documentation.
The trait you're trying to use is in fact inside laravel/ui, so you should still require this package in your composer.json: https://github.com/laravel/ui/blob/2.x/auth-backend/AuthenticatesUsers.php
I would also try running composer dump-autoload after installing the laravel/ui package (this should clear any cached autoloaders).
Also, please don't forget to properly import the AuthenticatesUsers trait in your controller:
use Illuminate\Foundation\Auth\AuthenticatesUsers;
...
class LoginController extends Controller
{
use AuthenticatesUsers;
...
}
I am using Alchemy API for filter out some data. Everything works fine in the native code. But when i used it in my Laravel Controller it throws Cannot redeclare class. My controller,alchemyapi.php and example.php are in the same directory. Here is how i include alchemyapi.php in native code
<?php
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI("MY API KEY"); ?>
But when i include it in the controller it throws my the error. is there something i am missing ?
require_once 'alchemyapi.php';
$alchemyapi = new AlchemyAPI("MY API KEY");
The native code(example.php) works well without any issue. But in laravel controller it throws a error saying Cannot redeclare class AlchemyAPI
in alchemyapi.php line 20
Instead of using require_once use namespace in your alchemyapi.php and then use use for same namespace in your MyController
alchemyapi.php
<?php
namespace App\Http\Controller;
class AlchemyApi {
//your code
}
MyController.php
<?php
namespace App\Http\Controller;
use App\Http\Controller\AlchemyApi;
class MyController {
$alchemy = new AlchemyApi("Your_api_key");
}
OK, so what I think is happening is that alchemyapi.php is somehow already being included by the composer autoloader.
Try this.
Create the directory lib in the root of your project.
Move alchemiapi.php into lib.
Under the "autoload" section in your composer.json add the following code. Make sure the JSON is valid:
"files": [
"lib/alchemyapi.php",
],
Run composer dump-autoload. If it errors, your composer.json is invalid or you haven't put the file in the correct place.
Delete require_once 'alchemyapi.php'; from your controller.
When dealing with composer, this is how you deal with classes in the global namespace. After running composer it scan those directories in app for PSR-4 classes.
I can't be sure but I think that composer is looking for it and you are also manually requiring it. That would explain why PHP thinks you are redeclaring the class.
For implement of a Nested Set for my news category I want to use Baum package.
After installing this Package via Composer and add BaumServiceProvider to config/app.php providers, I try to install a new Model named Category via Below command:
php artisan baum:install MODEL
But I faced to the following error :
[InvalidArgumentException]
There are no commands defined in the "baum" namespace.
Of course I ran php artisan command and But there were no command named Baum on generated commands list.
What should I do?
First you have to add the code below in config/app.php:
Baum\Providers\BaumServiceProvider::class
If the problem still persists configuration files may be cached. Just call:
php artisan config:clear
Make sure that you added
Baum\Providers\BaumServiceProvider::class
To the providers array in the app.php file located in config/app.php
Whenever I know that I have added something into Laravel's core files, and it's not working from the command line, I typically just run
php artisan optimize
to regenerate all of the classes, and it will typically work. Running this command is something that I find myself doing fairly often.
In AppServiceProvider.php (app\Providers) you can modify register function: public function register()
{
$this->app->register(\Baum\Providers\BaumServiceProvider::class);
}
Not sure why 5.2 have error, just tweak a bit myself.
Try add this on APP/Console/kernel.php
protected $commands = [
//Commands\Inspire::class,
// Register Baum nestedset command
Commands\BaumCommand::class,
Commands\InstallCommand::class
];
and create two files and copy BaumCommand.php and InstallCommand in /vendor/baum/baum/src/Baum/console.
then change a namespace at the top.
namespace Baum\Commands;
to
namespace App\Console\Commands;
I am currently learning laravel 5 and wanted to implement the repository concept.
as I understand. I should put an ioc.php and the config folder and put my bindings their
Here is my config/ioc.php
<?php
App::bind('QuestionRepository', 'IQuestionRepository');
App::bind('AnswerRepository', 'IAnswerRepository');
I get an error Class 'App' not found in
try prefixing App with \ like \App
For my case in lumen 5.4, undefined 'App' class issue solved by facade definition:
use Illuminate\Support\Facades\App;
In my case, my .env file contained a value with spaces after checking out a new project.
Running php artisan optimize for the first time would throw this error because my Exception handler was trying to use the '\App' global alias for the App facade. Commenting that code showed the real error;
"Dotenv values containing spaces must be surrounded by quotes."