简体   繁体   中英

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

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

Try it without the all() . You can add where parameters if you wish:

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

or just simply pull the array:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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