我想使用 where
从我的表中选择一个对象,如下所示:
$obj = Product::where('column_name', '=', 'string')->get();
但是 $obj 在 json 中。
如何获取普通对象?
最佳答案
$product = Product::where('model','like', '%table%')
->orderBy('price', 'desc')
->get();
var_dump($product);
会给你 Eloquent 对象集合,它不是 jSON
var_dump($product->toJson());
会给你JSON对象
但您还应该考虑基本查询。
$product = DB::table('product')->select('id', 'model')
->where('product_id' , '=' , $id)
->get();
要收集所有对象,请使用:
$products = Product::all();
等等
$product = Product::find($id);
关于laravel - Eloquent ORM - 如何使用 WHERE 获取对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17763448/