如何从laravel php中的特定列检索数据库中的自定义数据

问题描述 投票:0回答:2

我在数据库中有一个表用户

id,name,users_type

有多种类型的users_type,如Admin,Sub Admin,Unsigned,Normal User

我想获得所有类型的users_type但不是管理员用户。

php laravel
2个回答
1
投票

如果您正在使用雄辩的模型

$users = User::where('users_type', '!=', 'Admin')->get();

使用查询生成器

$users = DB::table('users')->where('users_type', '!=', 'Admin')->get();

检查这个查询生成器https://laravel.com/docs/5.6/queries和Eloquent你可以看看这个https://laravel.com/docs/5.6/eloquent


0
投票
$users = User::where('users_type','<>','Admin')->get();

你想得到等于的结果,然后不需要添加=

如果你只想获得一个用户,那么使用qazxsw poi而不是qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.