I want to use "Jenssegers\Mongodb" package in a Laravel 5.5 app.
The package documentation tells to use:
use Jenssegers\Mongodb\Eloquent\Model;
class User extends Model {}
instead of:
use Illuminate\Database\Eloquent\Model;
class User extends Model {}
But, inUser model:
class User extends Authenticatable{}
and in "Illuminate\Foundation\Auth\User" class (what 'Authenticatable' refers to) it's using Illuminate\Database\Eloquent\Model not Jenssegers\Mongodb\Eloquent\Model.
I found this solution to extend what 'Authenticatable' extends directly in my model instead of extending 'Authenticatable' itself, so that I can use Jenssegers\Mongodb\Eloquent\Model;
Is there another better solution or should I make it like that??
use Jenssegers\Mongodb\Auth\User as Authenticatable;
then
class User extends Authenticatable
Related
I followed the installation guide https://vanilo.io/docs/3.x/installation for vanilo step by step. Once all steps were completed, I tried to start up the development server with php artisan serve
and it threw an error:
InvalidArgumentException
Class App\Models\User must extend or implement Konekt\User\Contracts\User.
The default user model has been configured to extend the Konekt user model as described in the installation guide:
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends \Konekt\User\Models\User
{
The boot method in AppServiceProvider contains:
$this->app->concord->registerModel(\Konekt\User\Contracts\User::class, \App\Models\User::class);
The error states that the user model needs to extend or implement a model from Contacts\User, and it does as declared in the Konekt\User\Models:
namespace Konekt\User\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Konekt\Enum\Eloquent\CastsEnums;
use Konekt\User\Contracts\Profile;
use Konekt\User\Contracts\User as UserContract;
use Konekt\User\Contracts\Profile as ProfileContract;
use Konekt\User\Events\UserWasActivated;
use Konekt\User\Events\UserWasCreated;
use Konekt\User\Events\UserWasDeleted;
use Konekt\User\Events\UserWasInactivated;
/**
* User Entity class
*
*/
class User extends Authenticatable implements UserContract
{
I've followed this installation guide twice over from scratch and it always leads to this error. I need help troubleshooting, as it appears everything is done properly.
Fixed by changing the namespace on the User model to default, despite the tutorial showing namespace App, I used namespace App\Models and that fixed it.
Is there a way I can include use Illuminate\Database\Eloquent\SoftDeletes;
and use SoftDeletes; on all my Models without needing to edit each model?
I want some way to make my models import it automatically.
You can create abstract Model, and put there SoftDeletes and inherit other models from this abstract model.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
abstract class AbstractModel extends Model
{
use SoftDeletes;
}
And for example User model will be:
namespace App\Models;
class User extends AbstractModel
{
}
I have installed the following package into my application so that users are able to follow and unfollow other users.
https://github.com/hypefactors/laravel-follow
In the documentation it states:
Preparing the Eloquent Models To allow an entity to be followed or to
follow other entities, the corresponding models have to implement an
interface and make usage of a trait.
Here's how we do it for a User and Company entity, where a user will
be able to follow a company and the company will be able to be
followed:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Hypefactors\Laravel\Follow\CanFollow;
use Hypefactors\Laravel\Follow\Contracts\CanFollowContract;
class User extends Model implements CanFollowContract
{
use CanFollow;
}
However my user model looks like this:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
I have tried including the files in various ways with no success. I assume its something to do with my user model class looking like this:
class User extends Authenticatable
and not this:
class User extends Model
Can anyone point me in the right direction?
If i do this:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Hypefactors\Laravel\Follow\CanFollow;
use Hypefactors\Laravel\Follow\Contracts\CanFollowContract;
class User extends Authenticatable implements CanFollowContract
{
use Notifiable;
use Uuids;
use CanFollow;
I get the following error:
Trait 'Hypefactors\Laravel\Follow\CanFollow' not found
I decided to change package to this: https://github.com/overtrue/laravel-follow which has worked nicely as expected.
#ceejayoz Thanks for your suggestions
I am running Lumen (5.6.3) (Laravel Components 5.6.*). I'm trying to build a Rest api using this tutorial(https://www.youtube.com/watch?v=eWoJ2YbdrWU&t=5s). Here is my games.php code:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Illuminate\Database\Eloquent\Model;
class games extends Model implements AuthenticatableContract, AuthenticatableContract, HasRoleAndPermissionContract
{
use HasApiTokens, Authenticatable, Authorizable;
protected $table="games";
protected $fillable = ['Team 1','Team 2','Score 1','Score 2','Game Date','Viewers'];
}
The error I get after running is:
PHP Fatal error: Trait 'App\HasApiTokens' not found in C:\Users...lumen-api\app\games.php on line 14
Fatal error: Trait 'App\HasApiTokens' not found in C:\Users\...lumen-api\app\games.php on line 14
In games.php line 14:
Trait 'App\HasApiTokens' not found
I did everything the same as the tutorial. I can't solve this error in part 2.
Do you have composer? Install that first. Then you need Laravel Passport.
Run composer require laravel/passport
Run php artisan passport:install from command line
Add add the Laravel\Passport\HasApiTokens trait to your App\User model.
Try again.
You must include this "use Laravel\Passport\HasApiTokens;" at the top in your user model.
Add the Laravel\Passport\HasApiTokens trait to your App\User model. This trait will provide a few helper methods to your model which allow you to inspect the authenticated user's token and scopes:
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
}
First of all apologize for the basic question but I'm new in both Laravel and Lumen and trying to learn it.
I'm trying to login user using Lumen but I've got errors. What I'm trying to write is
if (auth()->attempt(...) { }
Tried also another approach like this
if (\Auth::attempt(...) { }
Both ways the error is
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given
I'm sure also that I validate all the inputs from the form.
It seems your User model extends Model instead of Authenticatable. Your User model should look like this:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
....
Make sure you didn't forget to implement the Authenticatable in the model, like:
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
and Model implements it
class User extends Model implements AuthenticatableContract {
use Authenticatable;
...
}