【发布时间】:2016-11-22 15:34:50
【问题描述】:
在 Laravel 5.2 中有 $client->id 没有返回正确值的 OauthClient 模型。
"lucadegasperi/oauth2-server-laravel": "^5.1" 用于迁移 $table->string('id', 40)->primary();
但是,当在刀片模板中使用 $client->id 时,我会返回 "0" 。使用 dd($client) 在 id 属性中显示正确的值。
可能出了什么问题?
dd() 的模型输出
OauthClient {#254 ▼
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:7 [▼
"id" => "wISw4JmlMQCCrMupjojcuDTK3k4hwtkb"
"secret" => "nnw3CPTzeQSIfT4KpR0d3XzWIKKoghB3"
"name" => "http://example.com"
"package" => "free"
"user_id" => 2
"created_at" => "2016-07-19 15:36:28"
"updated_at" => "2016-07-19 15:36:28"
]
#original: array:7 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#fillable: []
#guarded: array:1 [▼
0 => "*"
]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
来自“show create table oauth_clients”的表结构
CREATE TABLE `oauth_clients` (
`id` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`secret` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`package` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `oauth_clients_id_secret_unique` (`id`,`secret`),
KEY `oauth_clients_user_id_foreign` (`user_id`),
CONSTRAINT `oauth_clients_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
【问题讨论】:
-
你能把
dd($client)的输出贴出来 -
数据模型中包含
id属性的情况并不常见。通常所有属性都保存在一个属性数组中,并且有一个神奇的__get方法可以获取适当的属性。我们需要看看你的OauthClientmodel 是什么样子的。 -
添加 dd() 输出和创建表语法
标签: php laravel oauth laravel-5 eloquent