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
Related
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 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
I am working on an Lumen project.
I try to use
Artisan::call('my-command')
But PHP says me the class Artisan is not defined.
I have already enable Facade with the following command :
$app->withFacades();
So the Log class works after use Log; line.
I have already add the use Artisan line.
But it doesn't works.
The following command works in CLI:
php artisan my-command
Do you have any idea ?
This error occured because I use a wrong use sentence :
use Artisan; // Doesn't work
I must use this absolute use sentence :
use Illuminate\Support\Facades\Artisan;
I hope it will be helpful
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."