我是laravel的新手,使用Laravel 5.3。
我在laravel模型中创建了一个用于用户登录的check()
函数
在这里我得到所有数据形式的数据库使用默认$this->all();
这给我一个大的多维度
阵列。
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\wn_users Object
(
[table:protected] => wn_users
[timestamps] =>
[fillable:protected] => Array
(
[0] => role_id
[1] => firstname
[2] => lastname
[3] => username
[4] => email
[5] => password
[6] => companyname
[7] => country_id
[8] => description
[9] => ip
[10] => update_date
[11] => status
)
[connection:protected] =>
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[user_id] => 1
[role_id] => 1
[firstname] => Aman kumar
[lastname] => --
[username] => Aman kumar
[email] => aman.imaxtechnologies@gmail.com
[password] => e10adc3949ba59abbe56e057f20f883e
[companyname] => Imax
[country_id] => 123
[description] => Testing
[ip] => 192.168.1.1
[update_date] => 2017-03-20
[status] => 0
[created_at] =>
[updated_at] =>
)
[original:protected] => Array
(
[user_id] => 1
[role_id] => 1
[firstname] => Aman kumar
[lastname] => --
[username] => Aman kumar
[email] => aman.imaxtechnologies@gmail.com
[password] => e10adc3949ba59abbe56e057f20f883e
[companyname] => Imax
[country_id] => 123
[description] => Testing
[ip] => 192.168.1.1
[update_date] => 2017-03-20
[status] => 0
[created_at] =>
[updated_at] =>
)
[casts:protected] => Array
(
)
[dates:protected] => Array
(
)
[dateFormat:protected] =>
[appends:protected] => Array
(
)
[events:protected] => Array
(
)
[observables:protected] => Array
(
)
[relations:protected] => Array
(
)
[touches:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
)
)
)
但我想只在laravel中获得'attributes:protected'
表格整数组。我已经尝试了
echo $data = $this->getAttributes()['firstname'];
但这会返回错误
Undefined index: firstname
请帮我解决我的问题
提前感谢您的帮助和时间。
答案 0 :(得分:1)
一种非常简单的方法:
$arr = $this->all()->toArray();
var_dump($arr); // oh~ array data!
答案 1 :(得分:0)
所以你有一个带属性的集合。您可以像For i = (1 + randomStart) To endPoint Step xInterval
Do While Not IsEmpty(ActiveCell)
Set rng = InputRng.Cells(i, endPoint)
Do While IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
For j = 1 To endPoint2 Step xInterval
Set rng2 = InputRng.Cells(j, endPoint2)
End If
If OutRng Is Nothing Then
Set OutRng = rng
Else
Set OutRng = Application.Union(OutRng, rng, rng2)
End If
一样访问它们。或者,如果您想对所有项目执行某些操作,请使用每种方法:
$collection->first()->firstname