I am a beginner of using Laravel, in this case i am going to get a data(price) from database and then define it as an variables($price) for further process.
The problem is when i define the variables $price and try to echo it to test the out come, it occurred a error called "Object of class stdClass could not be converted to string".
I try to figure out the problems these day, realize that there are something wrong on the result from the database. It changes to an Object of class stdClass instead of an array? However, when i use all the solution that i found on the internet it still doesn't work........
Solution i have already tried:
$array = json_decode(json_encode($price), true);
$price = array();
->toArray(); //Used in my code
Below are my Controller.blade.php
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Menu $menu
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $day)
{
$opt1 = $request->post('dishopt1');
$price1 = DB::table('dishes')->select('price', 'chg_porridge')->where([
['name', '=', $opt1],
])->get()->toArray();
$price1 = $price1[0];
echo $price1;
}