You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there, I swapped my User and PersonalAccessToken (using Sanctum) over to Datastore - I am able to insert models when I use User::create([ 'xxx' ]); or PersonalAccessToken::create([ 'xxx' ]); however when I do something like the following
I am getting errors like User::__key__ not defined. However when I looked deeper into the Appsero Model, key looks like it needs to be a class object with a function path that returns a 0 based index with either key or name.
I am happy to create a PR if I'm right in thinking that something is missing - otherwise if I am using this wrong with my models, I would love to know how they are supposed to look. It has been a bit tricky getting Datastore working in Laravel but it looks like the fundamentals are working - thank you for this library.
I've added my models below - they are very simple.
DatastoreAuth
namespaceApp\Models;
useIlluminate\Database\Eloquent\Factories\HasFactory;
useIlluminate\Auth\Authenticatable;
useIlluminate\Auth\MustVerifyEmail;
useIlluminate\Auth\Passwords\CanResetPassword;
useIlluminate\Contracts\Auth\Access\AuthorizableasAuthorizableContract;
useIlluminate\Contracts\Auth\AuthenticatableasAuthenticatableContract;
useIlluminate\Contracts\Auth\CanResetPasswordasCanResetPasswordContract;
useAppsero\LaravelDatastore\Eloquent\Model;
useIlluminate\Foundation\Auth\Access\Authorizable;
class DatastoreAuth extends Model implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, MustVerifyEmail;
}
PersonalAccessToken (The replacement for the Sanctum default)
<?phpnamespaceApp\Models;
useAppsero\LaravelDatastore\Eloquent\Model;
useLaravel\Sanctum\Contracts\HasAbilities;
class PersonalAccessToken extends Model implements HasAbilities
{
/** * The attributes that should be cast to native types. * * @var array */protected$casts = [
'abilities' => 'json',
'last_used_at' => 'datetime',
];
/** * The attributes that are mass assignable. * * @var array */protected$fillable = [
'name',
'token',
'abilities',
];
/** * The attributes that should be hidden for serialization. * * @var array */protected$hidden = [
'token',
];
/** * Get the tokenable model that the access token belongs to. * * @return \Illuminate\Database\Eloquent\Relations\MorphTo */publicfunctiontokenable()
{
return$this->morphTo('tokenable');
}
/** * Find the token instance matching the given token. * * @param string $token * @return static|null */publicstaticfunctionfindToken($token)
{
if (strpos($token, '|') === false) {
returnstatic::where('token', hash('sha256', $token))->first();
}
[$id, $token] = explode('|', $token, 2);
if ($instance = static::find($id)) {
returnhash_equals($instance->token, hash('sha256', $token)) ? $instance : null;
}
}
/** * Determine if the token has a given ability. * * @param string $ability * @return bool */publicfunctioncan($ability)
{
returnin_array('*', $this->abilities) ||
array_key_exists($ability, array_flip($this->abilities));
}
/** * Determine if the token is missing a given ability. * * @param string $ability * @return bool */publicfunctioncant($ability)
{
return ! $this->can($ability);
}
}
And my User Model
<?phpnamespaceApp\Models;
useIlluminate\Contracts\Auth\MustVerifyEmail;
useIlluminate\Database\Eloquent\Factories\HasFactory;
useIlluminate\Notifications\Notifiable;
useLaravel\Sanctum\HasApiTokens;
class User extends DatastoreAuth
{
use HasApiTokens, HasFactory, Notifiable;
/** * The attributes that are mass assignable. * * @var array<int, string> */protected$fillable = [
'name',
'password',
];
/** * The attributes that should be hidden for serialization. * * @var array<int, string> */protected$hidden = [
'password',
'remember_token',
];
/** * The attributes that should be cast. * * @var array<string, string> */protected$casts = [
'email_verified_at' => 'datetime',
];
}
The text was updated successfully, but these errors were encountered:
createToken() function is not working correctly as we haven't implemented the relationship functionality yet. I am still working on this. Hopefully, "relationship" will be available in the next couple of days. After finishing it, I will let you know here.
Hey there, I swapped my User and PersonalAccessToken (using Sanctum) over to Datastore - I am able to insert models when I use
User::create([ 'xxx' ]);
orPersonalAccessToken::create([ 'xxx' ]);
however when I do something like the followingI am getting errors like
User::__key__
not defined. However when I looked deeper into the Appsero Model, key looks like it needs to be a class object with a function path that returns a 0 based index with either key or name.I am happy to create a PR if I'm right in thinking that something is missing - otherwise if I am using this wrong with my models, I would love to know how they are supposed to look. It has been a bit tricky getting Datastore working in Laravel but it looks like the fundamentals are working - thank you for this library.
I've added my models below - they are very simple.
DatastoreAuth
PersonalAccessToken (The replacement for the Sanctum default)
And my User Model
The text was updated successfully, but these errors were encountered: