我花了几个小时寻找这个。
我对 Laravel 非常陌生(来自 CodeIgniter),我正在尝试以 Laravel 的方式做所有事情,而不是在任何地方使用纯 php/sql,除非非常必要。
$role_id = Role::select('role_id') ->where('type','Admin') ->get(); var_dump($role_id);
我正在尝试获取 $role_id。
var_dump 给了我这个。
object(Illuminate\Database\Eloquent\Collection)#249 (1) { ["items":protected]=> array(1) { [0]=> object(App\Role)#252 (26) { ["connection":protected]=> string(5) "mysql" ["table":protected]=> string(5) "roles" ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["attributes":protected]=> array(1) { ["role_id"]=> int(99) } ["original":protected]=> array(1) { ["role_id"]=> int(99) } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=> bool(true) ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["fillable":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } } } }
我期望只有一个 mysql 结果行而不是这个。
我正在寻找的就是这个["role_id"]=> int(99)
。
我缺少一个直接获取它的函数,我无法从文档中找到它。
$role_id->role_id
给我找不到财产。
RISEBY
泛舟湖上清波郎朗
红颜莎娜