简体   繁体   English

如何从数组的数据库中获取信息?

[英]How could I got info from data base on an array?

I'm trying to Extract info from my data base with Laravel eloquent, looking for it returns me an array with all the data I have two tables parameter_type and parameters_type and are related by the id of parameter_type and on parameters by parameter_type that save the id 我正在尝试使用Laravel雄辩地从我的数据库中提取信息,寻找它返回一个包含所有数据的数组,我有两个表parameter_type和parameters_type并与parameter_type的ID相关联,并且与parameter_type的参数相关联(保存ID)

I have tried this but don't got so far yet 我已经尝试过了,但是还没有到此为止

$parameters = parameters::all()->pluck('name','id')->toArray();

DB::table('parameters')->join('parameter_type','parameters.parameter_type','=','parameter_type.id')->select('parameters.name')->where('parameters.parameter_type','=','8')->get();

I expect that it returns me an array with all the info that it found on the table but the first code return me all data from table and the second throws an error 我希望它返回一个包含在表中找到的所有信息的数组,但是第一个代码返回我表中的所有数据,第二个代码返回错误

Object of class Illuminate\\Support\\Collection could not be converted to number 无法将Illuminate \\ Support \\ Collection类的对象转换为数字

Try it without the all() . 不带all()尝试一下。 You can add where parameters if you wish: 您可以根据需要添加where参数:

$parameters = parameters::where('some_col', $someParameter)->pluck('name','id')->toArray();

or just simply pull the array: 或者只是简单地拉数组:

$parameters = parameters::pluck('name','id')->toArray();

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

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