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
{{ message }}
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
the problem is that laravel toArray add pivot data and if it include uuid it will make utf8 error
i fixed this by removing pivot from the array
if (isset($array['pivot'])){
unset($array['pivot']);
}
this is the new trait toArray
public function toArray()
{
$uuidAttributes = $this->getUuidAttributes();
$array = parent::toArray();
if (! $this->exists || ! is_array($uuidAttributes)) {
return $array;
}
foreach ($uuidAttributes as $attributeKey) {
if (! array_key_exists($attributeKey, $array)) {
continue;
}
$uuidKey = $this->getRelatedBinaryKeyName($attributeKey);
$array[$attributeKey] = $this->{$uuidKey};
}
if (isset($array['pivot'])){
unset($array['pivot']);
}
return $array;
}
Schema::create('roles', function (Blueprint $table) {
$table->uuid('id');
$table->string('name')->unique();
});
Schema::create('permissions', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
});
Schema::create('permission_role', function (Blueprint $table) {
$table->uuid('permission_id')->index()->foreign('permission_id')->references('slug')->on('permissions')->onDelete('cascade');;
$table->uuid('role_id')->index()->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
class Role extends Model
{
use HasBinaryUuid;
protected $uuids = [
'id'
];
public function permissions()
{
return $this->belongsToMany(Permission::class,'permission_role','role_id','permission_id');
}
}
class Permission extends Model
{
use HasBinaryUuid;
protected $uuids = [
'id'
];
public function roles()
{
return $this->belongsToMany(Role::class,'permission_role','permission_id','role_id');
}
}
Route::any('roles', function () {
return Role::with('permissions')->get() ;
});
Malformed UTF-8 characters, possibly incorrectly encoded
i think the model to Array not working on collections and join
any help
The text was updated successfully, but these errors were encountered:
the problem is that laravel toArray add pivot data and if it include uuid it will make utf8 error
i fixed this by removing pivot from the array
if (isset($array['pivot'])){
unset($array['pivot']);
}
this is the new trait toArray
Malformed UTF-8 characters, possibly incorrectly encoded
i think the model to Array not working on collections and join
any help
The text was updated successfully, but these errors were encountered: