laravel / telescope

An elegant debug assistant for the Laravel framework.
https://laravel.com/docs/telescope
MIT License
4.77k stars 560 forks source link

When saving a model I use several primary_keys #1453

Closed akazakbaev closed 3 months ago

akazakbaev commented 3 months ago

Telescope Version

5

Laravel Version

11

PHP Version

8.2

Database Driver & Version

No response

Description

when I want to save the model, an error occurs

model use multiple primary_key

"message": "array_key_exists(): Argument #1 ($key) must be a valid array offset type",

Steps To Reproduce

DocumentUser::create([ 'document_uuid' => $uuid, 'employee_id' => 1 ]);

class DocumentUser extends Model { protected $primaryKey = ['document_uuid', 'employee_id']; public $incrementing = false; }

"message": "array_key_exists(): Argument #1 ($key) must be a valid array offset type", "exception": "TypeError", "file": "/var/www/html/api-sed/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php", "line": 451,

{ "file": "/var/www/html/api-sed/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php", "line": 451, "function": "array_key_exists" }, { "file": "/var/www/html/api-sed/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php", "line": 1967, "function": "getAttribute", "class": "Illuminate\Database\Eloquent\Model", "type": "->" }, { "file": "/var/www/html/api-sed/vendor/laravel/telescope/src/FormatModel.php", "line": 25, "function": "getKey", "class": "Illuminate\Database\Eloquent\Model", "type": "->" },

Lakshan-Madushanka commented 3 months ago

I think this is not a telescope issue. Eloquent doesn't support composite keys. https://github.com/laravel/framework/issues/5517

driesvints commented 3 months ago

Thanks @Lakshan-Madushanka