Home >Backend Development >PHP Tutorial >laravel Select在什么情况下使用

laravel Select在什么情况下使用

PHPz
PHPzOriginal
2016-06-06 20:34:003346browse

laravel Select在“不想要数据表的所有列”的情况下使用,其使用语法是“$user = DB:table('users')->select('name','telephone as telephone')->get();”。

laravel Select在什么情况下使用

laravel5.4之查询构建器select查询总结

1、如果不想要数据表的所有列,使用select方法,指定需要的字段。

$user = DB:table('users')->select('name','telephone as telephone')->get();

2、如果返回不重复的结果集加上distinct方法。

$address = DB:table('address')->distinct()->get();

3、如果已经有一个查询构建器实例,想添加一个查询列到已存在的select子句,用addSelect方法。

$query = DB::table('users')->select('name');
$users = $query->addSelect('age')->get();

 更多相关知识,请访问PHP中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn