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

laravel Select在什么情况下使用

PHPz
Release: 2020-09-05 10:18:39
Original
3324 people have browsed it

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();
Copy after login

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

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template