I created a project in laravel 5.2, and moving this to laravel 5.3
For this, I created a brand new laravel 5.3 project folder where I am copying views and controllers to the new project. When trying to get Auth working, I see a lot of "undefined class" errors.
By checking laravel documentation, I saw this, where I am stuck now
https://laravel.com/docs/5.3/authentication#retrieving-the-authenticated-user
so, in app.php I see
'Auth' => Illuminate\Support\Facades\Auth::class,
when in my controller, I get "Undefined class Auth" on this
use Auth;
this "undefined class" is solved by changing that line to
use Illuminate\Support\Facades\Auth;
first thing, why can't I just use "use Auth;" ?
In my controller file, I get "undefined class" error on DB, Auth and File
use DB;
use Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use File;
in my app.php file, these names are aliased as
'App' => Illuminate\Support\Facades\App::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
so I wonder what could be wrong with the aliases ?
Next to this, when trying to get the authenticated user, as described in the documentation, this line is enough
Auth::user()
Here, "user" throws this error:
Method 'user' not found in \Illuminate\Support\Facades\Auth
I checked around using google, comparing files in my Laravel 5.2 against my Laravel 5.3 folders, but did not see any solutions. Maybe someone here has the answer? It worked in my Laravel 5.2 project as described in the link above.
thank you
UPDATE
just try to rebuild the project by these commands in this order:
composer update
php artisan config:clear
composer dump-autoload
but still no progress
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 upgrading application written in Laravel 4.2 to Laravel 5.2.
I have long namespaces for my controllers and want to shorten them.
For example:
CustomServiceProvider.php
public function register()
{
$this->app->bind('Shortname\Somecontroller', 'Really\Really\Long\Name\Somecontroller');
}
routes.php
$router->get('someroute', ['uses' => 'Shortname\Somecontroller#someFunction']);
was possible inside custom service provider and works in Laravel 4.2 and Larave 5.1. After I've started migrating to Laravel 5.2 it stopped working.
Closest I came to the solution was this issue report: https://github.com/laravel/framework/issues/14920 but it doesn't work either.
This works for example:
routes_alternative.php
$router->get('someroute', ['uses' => 'Really\Really\Long\Name\Somecontroller#someFunction']);
I've tried Really\Really\Long\Name\Somecontroller::class and moving everything to RouteServiceProvider. I've also tried artisan route:clear,artisan cache:clear, artisan dump-autoload, artisan clear-compiled and all sorts of other composer and artisan shenanigans.
All actions result in exception:
ReflectionException in Route.php line 280:
Class Shortname\Somecontroller does not exist
Does someone have similar expiriences and was able to solve it?
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.
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."
What I did:
Added "laravel/socialite": "~2.0" to composer.json
Run composer update
Added provider 'Laravel\Socialite\SocialiteServiceProvider' to app.php
Added alias 'Socialite' => 'Laravel\Socialite\Facades\Socialite' to app.php
After all this steps I created a new Controller Class which looks like that:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AuthController extends Controller {
public function login()
{
return \Socialite::with('facebook')->redirect();
}
}
But i still got this error: PHP Fatal error: Class '\Socialite'
Edit
composer dump-autoload fixed probably the error, but it's still not working correctly.
In your Controllers file add
use Laravel\Socialite\Facades\Socialite;
Just below use Illuminate\Http\Request; in your controller add use Socialize;
Check if you have set your alias as "Socialize" as in the Socialite docs says to do this way:
'Socialize' => 'Laravel\Socialite\Facades\Socialite',
It as very confusing to me as well
I had the same issue. Clearing the config cache helped me in this situation:
php artisan config:clear
First of all use ::class, on your config/app.php
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
Second, call the class in your controller
use Socialite;
Third, try clear the config
php artisan config:clear
And lastly check the redirect URL if its working
http://yoursite.com/your_redirect
If anyone still encounters this problem even after trying above solutions, please clear the cache. Most of the time classes and all are cached because of which this error occurs.
php artisan config:clear
'Socialite' => 'Laravel\Socialite\Facades\Socialite' is a mistake that I did too.
It must be declared as 'Socialite' => Laravel\Socialite\Facades\Socialite::class
I had the exact same problem and after the usual half hour of raging I realised that there was a trailing space at the end of my registration line i.e.
'Laravel\Socialite\SocialiteServiceProvider ',
Once I'd removed the space funnily enough it worked!
'Laravel\Socialite\SocialiteServiceProvider',
Once again the woes of copy and paste raise their ugly heads!
in laravel 6 or above, try running this command
composer require laravel/socialite