简体   繁体   English

Laravel从没有stdClass对象的数据库中仅获取一个值

[英]Laravel fetch only one value from databse without stdClass Object

Hello people here is my code below... 大家好,这是我的以下代码...

        $uid = DB::table('users')
                     ->where('email', '=', Input::get('email'))
                     ->select('email')
                     ->get();

                    print_R ($uid);

this will output Array ( [0] => stdClass Object ( [email] => myemail@someemail.om ) ) I want only [email] => myemail@someemail.om so that i can save in session, Without using foreach loop can we get an outfput [0] => stdClass Object ???? 这将输出Array ( [0] => stdClass Object ( [email] => myemail@someemail.om ) )我只想要[email] => myemail@someemail.om这样我就可以保存在会话中,而无需使用foreach loop我们可以得到输出[0] => stdClass Object吗?

If you are using Laravel 4, there is a great helper that does just what you need. 如果您使用的是Laravel 4,那么有个出色的帮手可以满足您的需求。 Here is the update code for your example : 这是您的示例的更新代码:

$uid = DB::table('users')
        ->where('email', '=', Input::get('email'))
        ->pluck('email');

As for laravel3 the docs state that upper example changes to : 至于laravel3,文档指出上面的示例变为:

$uid = DB::table('users')
        ->where('email', '=', Input::get('email'))
        ->only('email');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM