Closed shep1990 closed 8 years ago
Do you have Authenticatable
on your User
model? If you have your code up on GitHub I can take a closer look, but there could be a few things going on. Not sure if you can share or not.
Hi there,
Thank you very much for getting back to me! I do have Authenticatable in my User model, I have put my code on github, https://github.com/shep1990/messenger. This is just a clean instillation of Laravel with Messenger installed, I wanted to see if it happened on a clean install.
Thanks again.
Richard.
Having the same issue.
Of course.. the example code of MessagesController.php is using a user with the ID of 1. If the user does not exist an error will be thrown.
I have updated my code to this:
MessagesController.php
public function __construct()
{
$user = Auth::user();
}
The constructor in the example controller should be removed in the real application, and a better authentication process should be put into place. The initial code is just for testing purposes. Once this is removed, you should be all set...
/**
* Just for testing - the user should be logged in. In a real
* app, please use standard authentication practices
*/
public function __construct()
{
$user = User::find(1);
Auth::login($user);
}
I am having a similar problem, something like :: FatalErrorException in User.php line 10: Interface 'Illuminate\Contracts\Auth\Authenticable' not found
Hi Add code like below in User.php Model File
<?php
namespace App;
use Eloquent;
// use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
class User extends Eloquent implements Authenticatable
{
use AuthenticableTrait;
// ... Other Code
}
still not working help plz..
In previous versions of Laravel, you could access session variables or the authenticated user in your controller's constructor. This was never intended to be an explicit feature of the framework. In Laravel 5.3, you can't access the session or authenticated user in your controller's constructor because the middleware has not run yet.
As an alternative, you may define a Closure based middleware directly in your controller's constructor. Before using this feature, make sure that your application is running Laravel 5.3.4 or above:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class MessengerController extends Controller
{
protected $user;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(function ($request, $next) {
$this->user = Auth::user();
return $next($request);
});
}
}
Or just don't try to get authenticated user in constructor and get in in other controller public methods by typehinting instance of \Illuminate\Http\Request
class or use Auth
facade.
public function index(Request $request)
{
$user = $request->user();
$user = Auth::user();
}
Do not change anything inside User.php (Model file), keep it as default, as it is at the time of installation of new laravel file. User.php file will be as it is as below, <?php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable;
class User extends Authenticatable { use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
I got this error when trying to use socialite. I checked both my 'social_providers' table and 'users' table and realise that the row in 'social_providers' table was referencing the wrong user_id. So I just changed the ids to match and I stopped getting this error.
Not sure whether this will help anyone.
i have same problem what can i do ??
you need to return $user after the create() method.
Probaste cambiando Auth::login($user->id) a Auth::login($user)
my issue ...
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, null given, called in C:\xampp\htdocs\writersBay\app\Http\Controllers\Admin\Auth\RegisterController.php
@nickforbizz i too having the same issue.. I'm on the middle of 5.1 to 5.2 now... what can i do now?
I think in the user model, you should extend authenticatable instead of model and also import it...
On Tue, Jun 25, 2019, 10:30 AM Karthik SWOT notifications@github.com wrote:
@nickforbizz https://github.com/nickforbizz i too having the same issue.. I'm on the middle of 5.1 to 5.2 now... what can i do now?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cmgmyr/laravel-messenger/issues/82?email_source=notifications&email_token=AJQ2JASCCGBRXE44IOXZW5TP4HCQ7A5CNFSM4BRDDU72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYPJ67Q#issuecomment-505323390, or mute the thread https://github.com/notifications/unsubscribe-auth/AJQ2JAWVEXR7JMM6ONLJPEDP4HCQ7ANCNFSM4BRDDU7Q .
Laravel 6.2 I got the same issue. Different from the above. My User model is
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
abstract class User extends Authenticatable
{
use Notifiable,SoftDeletes;
...
}
And I am building a SPA by vue and Laravel, I use api
as my guards instead of web
in config/auth.php
'guards' => [
// 'web' => [
// 'driver' => 'session',
// 'provider' => 'users',
// ],
'api' => [
'driver' => 'token',
// 'provider' => 'users',
'provider' => getSubdomain(),
'hash' => false,
],
],
...
'providers' => [
// 'users' => [
// 'driver' => 'eloquent',
// 'model' => App\Models\User::class,
// ],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
'worker' => [
'driver' => 'eloquent',
'model' => App\Models\Worker::class
],
],
then I add
'index' => [
'driver' => 'eloquent',
'model' => null
],
to providers
in config/auth.php
I fixed it.
so, you need to provide a provide
for each part even if it is empty.
hope it can helps you, sorry for poor in English
I got this error when trying to use socialite. I checked both my 'social_providers' table and 'users' table and realise that the row in 'social_providers' table was referencing the wrong user_id. So I just changed the ids to match and I stopped getting this error.
Not sure whether this will help anyone.
Thanks,
gfffh
Hi there,
I am getting the following issue whenever I run the messenger application and since I am new to Laravel I am not 100% sure what is causing this problem. I have tried Googling the error but I am not getting a clear answer on this.
Argument 1 passed to Illuminate\Auth\Guard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given
Could you help?
Thanks,
Rich