I'm using UUIDs as the ID for all my Models which causes to break the Edit Profile Page in Voyager. When saving the changes I ran into the following error:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for uuid: "25" (SQL: select * from "users" where "users"."id" = 25 limit 1)
The ID of my User is "25a810a0-1a07-11e7-ac77-eb5659a75a9e"
Try editing BREAD for users in the database section. Change id input type from Number to Text.
@abdgad Did not help... same outcome
I also noticed that the Edit and Delete-Links in the Browse-Table of Users treat the ID as an Integer. Link is /admin/users/25/edit instead of /admin/users/25a810a0-1a07-11e7-ac77-eb5659a75a9e/edit
After some research, it turned out that Laravel was casting the id to int by default. You need to modify your User model and set public $incrementing = false;.
More info here.
My User Model has $incrementing set to false already.
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Authenticatable
{
use Notifiable;
use Uuids;
use SoftDeletes;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* 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',
];
}
If I call User::all() the ID is returned correctly, so the error seems to be somewhere else.
array(23) {
["id"]=>
string(36) "25a810a0-1a07-11e7-ac77-eb5659a75a9e"
[...]
This is my UUID setup, in case you or someone else wants to reproduce:
https://medium.com/@steveazz/setting-up-uuids-in-laravel-5-552412db2088
Sure,
<?php
namespace App;
use Webpatser\Uuid\Uuid;
trait Uuids
{
/**
* Boot function from laravel.
*/
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->{$model->getKeyName()} = Uuid::generate()->string;
});
}
}
I'm using the exact same thing for other models, and they work fine with Voyager.
You need to tell Voyager to use your custom model. In your AppServiceProvider, add Voyager::useModel('User', \App\User::class);.
You should also extend TCG\Voyager\Models\User to avoid issues.
Okay, I figured it out. What worked and what I forgot to change is in the edit the BREAD in the admin panel, there was still a reference to TCG\Voyager\Models\User.
Thanks @abdgad for your help!
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
After some research, it turned out that Laravel was casting the
idtointby default. You need to modify your User model and setpublic $incrementing = false;.More info here.