F
Filament5mo ago
hannes

SQLSTATE[HY000]: General error: 1364 Field 'tokenable_type' doesn't have a default value

Hello everyone I ran into a problem in the Api-service plugin again. This time the error is :
SQLSTATE[HY000]: General error: 1364 Field 'tokenable_type' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'tokenable_type' doesn't have a default value
Although the documentation says that everything should be connected automatically, but I still have errors (I assume because of multi-tenancy) The plugin Model code and other necessary codes are provided below. Token.php (its plugin model) :
<?php

namespace Rupadana\ApiService\Models;

use App\Models\Company;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Laravel\Sanctum\PersonalAccessToken;

class Token extends PersonalAccessToken
{
use HasFactory;

public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
protected $table = 'personal_access_tokens';
}
<?php

namespace Rupadana\ApiService\Models;

use App\Models\Company;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Laravel\Sanctum\PersonalAccessToken;

class Token extends PersonalAccessToken
{
use HasFactory;

public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
protected $table = 'personal_access_tokens';
}
api-service.php:
<?php

// config for Rupadana/ApiService
return [
'navigation' => [
'group' => [
'token' => 'Company',
],
],
];
<?php

// config for Rupadana/ApiService
return [
'navigation' => [
'group' => [
'token' => 'Company',
],
],
];
Comapny.php:
<?php

namespace App\Models;
use ...
class Company extends Model
{
protected $fillable = [
'user_id',
'name',
'short_name',
'type',
];
public static array $allowedFields = [
'name'
];

// Which fields can be used to sort the results through the query string
public static array $allowedSorts = [
'name',
'created_at'
];

// Which fields can be used to filter the results through the query string
public static array $allowedFilters = [
'name'
];
public function token(): HasMany
{
return $this->hasMany(Token::class);
}
<?php

namespace App\Models;
use ...
class Company extends Model
{
protected $fillable = [
'user_id',
'name',
'short_name',
'type',
];
public static array $allowedFields = [
'name'
];

// Which fields can be used to sort the results through the query string
public static array $allowedSorts = [
'name',
'created_at'
];

// Which fields can be used to filter the results through the query string
public static array $allowedFilters = [
'name'
];
public function token(): HasMany
{
return $this->hasMany(Token::class);
}
5 Replies
hannes
hannes5mo ago
help pls))))
JJSanders
JJSanders5mo ago
THe error is in your face. SQLSTATE[HY000]: General error: 1364 Field 'tokenable_type' doesn't have a default value
hannes
hannes5mo ago
Friend, I understand this perfectly well and I understand what I could do with normal Laravel application development, but I use a plugin where it should be automated, I fixed this error, but after this error the plugin cannot find the company id for no reason, although all the connections are present
JJSanders
JJSanders5mo ago
Was trying to help and definetely not to be mean. What plugin are you trying to install?
hannes
hannes5mo ago
Yes, I'm not negative, I honestly don't know how my translator translates, but I understand that people here are trying to help newcomers like me. And the Api-service plugin : https://filamentphp.com/plugins/rupadana-api-service
Filament
API Service by Rupadana - Filament
A simple API service for supporting Filament resources.