I want to select an object from my table using where, like this:
$obj = Product::where('column_name', '=', 'string')->get();
But $obj is in json.
How can I get a normal object?
$product = Product::where('model','like', '%table%')
->orderBy('price', 'desc')
->get();
var_dump($product);
Will give you Eloquent Colection of objects and it isn't jSON
var_dump($product->toJson());
Will give you JSON Object
But you should also consider basic query.
$product = DB::table('product')->select('id', 'model')
->where('product_id' , '=' , $id)
->get();
For collection of all objects use:
$products = Product::all();
etc
$product = Product::find($id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With