Laravel获取属性数据 [英] Laravel Getting attributes data

查看:118
本文介绍了Laravel获取属性数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用Laravel 5.3的laravel新手.我在laravel模型中创建一个 check()函数用于用户登录在这里,我使用默认的 $ this-> all(); 来获取数据库的所有数据,这给了我很大的多元感数组.

I am new in laravel using Laravel 5.3. I am creating a check() function in laravel model for user login here i get all data form database useing default $this->all(); this return me a large multidymentional array .

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] => *
                        )

                )

        )

)

但是我只想得到'attributes:protected'在laravel中形成整个数组.我已经尝试过

But i want to get only 'attributes:protected' Form whole array in laravel . I have already tried

echo $ data = $ this-> getAttributes()['firstname']; 但这会返回错误

Undefined index: firstname

请帮助我解决问题

在此先感谢您的帮助和时间.

推荐答案

一种非常简单的方法:

$arr = $this->all()->toArray();

var_dump($arr); // oh~ array data!

这篇关于Laravel获取属性数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆