Larval Undefined index: field_name on mapping fiele - php

I am trying to edit code I found on a GitHub repository of Laravel Daily https://github.com/LaravelDaily/Laravel-8-Import-CSV.This is a system that matches the fields of the DB table and a .csv document before loading the data into the database. I'm trying to add some more fields to the table, but I'm getting an error Undefined index: phone_number because I don't have phone_number in the CSV document.
import_fields.blade
<tr>
#foreach ($csv_data[0] as $key => $value)
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-900">
<select name="fields[{{ $key }}]">
#foreach ($db_field as $field)
<option value="{{ (\Request::has('header')) ? $field : $loop->index }}"
#if ($key === $field) selected #endif>{{ $field }}</option>
#endforeach
</select>
</td>
#endforeach
</tr>
public function parseImport(CsvImportRequest $request)
{
if ($request->has('header')) {
$headings = (new HeadingRowImport)->toArray($request->file('csv_file'));
$data = Excel::toArray(new ContactsImport, $request->file('csv_file'))[0];
} else {
$data = array_map('str_getcsv', file($request->file('csv_file')->getRealPath()));
}
if (count($data) > 0) {
$csv_data = array_slice($data, 0, 2);
$csv_data_file = CsvData::create([
'csv_filename' => $request->file('csv_file')->getClientOriginalName(),
'csv_header' => $request->has('header'),
'csv_data' => json_encode($data)
]);
} else {
return redirect()->back();
}
// I have added this function here to get fields from my table
$contact = new Contact;
$table = $contact->getTable();
$db_field = \Schema::getColumnListing($table);
return view('import_fields', [
'headings' => $headings ?? null,
'csv_data' => $csv_data,
'csv_data_file' => $csv_data_file,
'db_field' => $db_field
]);
}
public function processImport(Request $request)
{
$data = CsvData::find($request->csv_data_file_id);
$csv_data = json_decode($data->csv_data, true);
foreach ($csv_data as $row) {
$contact = new Contact();
$table = $contact->getTable();
$db_field = \Schema::getColumnListing($table);
foreach ($db_field as $index => $field) {
if ($data->csv_header) {
if (array_key_exists($field, $request->fields)) {
$contact->$field = $row[$request->fields[$field]];
}
} else {
if (array_key_exists($index, $request->fields)) {
$contact->$field = $row[$request->fields[$index]];
}
}
}
$contact->save();
}
return redirect()->route('contacts.index')->with('success', 'Import finished.');
}
My migration file is here
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->string('first_name');
$table->string('middle_name')->nullable();
$table->string('last_name');
$table->string('email');
$table->string('phone_number');
});
Also, this is the structure of CSV I have
id first_name last_name email phone
When i do dd request here i get this result
public function processImport(Request $request)
{
dd($request->fields);
//RESULT
array:5 [▼
"id" => "id"
"first_name" => "first_name"
"last_name" => "last_name"
"email" => "email"
"phone" => "phone_number"
]
I get this error when I try to match phone from CSV with phone_numberfrom db
SQLSTATE[HY000]: General error: 1364 Field 'phone_number' doesn't have a default value (SQL: insert into contacts (email, first_name, id, last_name, updated_at, created_at) values (asorbie0#paginegialle.it, Ariela, 1, Sorbie, 2023-02-06 09:15:20, 2023-02-06 09:15:20))
[UPDATES]
if i add phone field on db table like this
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->string('first_name');
$table->string('middle_name')->nullable();
$table->string('last_name');
$table->string('email');
$table->string('phone')->nullable();
$table->string('phone_number')->nullable();
and but trying to match value off phone to phone_number when uploading data from excel file , now i am getting this error.
Undefined index: phone_number

Related

Laravel Display Array on blade with "unserialize"

im facing an issue to retrive an array from my database and display it on my blade.
So to understand my work, im actualy saving "Cart" informations on my "Orders Table" with Serialize the Products
public function store(Request $request)
{
$order = new Order();
$order->user_id = request('user_id');
$order->wilaya = request('wilaya');
$order->province = request('province');
$order->address = request('address');
$order->phone = request('phone');
$order->quantity = request('quantity');
$order->subtotal = request('total');
$order->status = request('status');
$products = [];
$i = 0;
foreach (Cart::content() as $product){
$products['product_' . $i][]= $product->name;
$products['product_' . $i][]= $product->options->color;
$products['product_' . $i][]= $product->price;
$products['product_' . $i][]= $product->options->size;
$products['product_' . $i][]= $product->options->image;
$products['product_' . $i][]= $product->qty;
$i++;
}
$order->products = serialize($products);
//dd($order);
if(Cart::count() <= 0){
return redirect('/products');
}else{
$order->save();
Cart::destroy();
return view('checkout.thankyou');
}
}
So when i try to retrive my data from the "Products" column with Unserialize on my show ressource
public function show($id)
{
$orderShow = Order::find($id);
$arr = unserialize($orderShow->products);
dd($arr);
return view('dashboard.order.show', compact('orderShow', 'arr'));
}
I get this result
array:2 [▼
"product_0" => array:6 [▼
0 => "T-Shirt Fashion 3"
1 => "black"
2 => 1300.0
3 => "S"
4 => "QFh840we7wZBKO790A6wFlipJB1ASaCpt3zJhJl8.png"
5 => 1
]
"product_1" => array:6 [▼
0 => "T-Shirt Fashion"
1 => "green"
2 => 1200.0
3 => "L"
4 => "CdMVwEJcMQbJjMp70UhRnkNQnRmWxzAGiWKxFeWN.png"
5 => 1
]
]
result of dd($arr) with image
I also try this
$json = json_encode(unserialize($orderShow->products));
And i get this result
"{"product_0":["T-Shirt Fashion 3","black",1300,"S","QFh840we7wZBKO790A6wFlipJB1ASaCpt3zJhJl8.png",1],"product_1":["T-Shirt Fashion","green",1200,"L","CdMVwEJcMQbJjMp70UhRnkNQnRmWxzAGiWKxFeWN.png",1]} ◀"
So i dont know how to deal with these arrays on my blade, i know that i need a Foreach loop to display it on the right way, but i have no idea how to proceed.
It can be a good idea to store your $products as an object (with key and value) instead of a pure array.
In your store function, you can try the following :
$products = [];
foreach (Cart::content() as $product) {
// similar to array_push()
$products[] = [
"name" => $product->name,
"color" => $product->options->color,
"price" => $product->price,
"size" => $product->options->size,
"image" => $product->options->image,
"qty" => $product->qty,
];
}
In your show function
public function show($id)
{
$orderShow = Order::find($id);
$products = unserialize($orderShow->products);
return view('dashboard.order.show', compact('orderShow', 'products'));
}
Then, in your blade template, if you need to display $products as a table:
<table>
<thead>
<tr>
<th>name</th>
<th>color</th>
<th>price</th>
<th>size</th>
<th>image</th>
<th>qty</th>
</tr>
</thead>
<tbody>
#foreach($products as $product)
<tr>
<td>{{$product['name']}}</td>
<td>{{$product['color']}}</td>
<td>{{$product['price']}}</td>
<td>{{$product['size']}}</td>
<td>{{$product['image']}}</td>
<td>{{$product['qty']}}</td>
</tr>
#endforeach
</tbody>
</table>
Quick tip, it is a good practice to define attributes (de)serialization in your model instead of your controller.
Have a look at Eloquent Mutator, and update your Order.php model with the following :
class Order extends Model {
// ...
public function setProductsAttribute($products)
{
$this->attributes['products'] = serialize($products);
}
public function getProductsAttribute()
{
return unserialize($this->attributes['products']);
}
// ...
}

How to update database base on laravel checkbox value

I load check boxes from database with they are checked or not,
<div class="row">
<div class="col-xs-12">
<div class="form-group">
#php
$json = $orders->data;
$json = json_decode($json, true);
$products = $json['order_info']['products'];
$data = '';
foreach ($products as $hitsIndex => $hitsValue) {
$data .= $hitsValue['type']. ', ';
}
$data = rtrim($data, ', ');
$agosProducts = Utility::constant('agos_products1');
#endphp
{{Html::validation($orders, 'product')}}
<label for="products" class="control-label">{{Translator::transSmart('app.Products', 'Products')}}</label><br><br>
#foreach($agosProducts as $product)
<label class="control-label "for="{{ $product['type'] }}">
<input id="{{ $product['type'] }}" name="{{ $product['type'] }}" type="checkbox" value="{{ $product['type'] }}"
#foreach ($products as $hitsIndex => $hitsValue)
#if(in_array($hitsValue['type'], $product)) checked=checked #endif
#endforeach
>
{{ $product['name'] }}
</label>
<br>
#endforeach
</div>
</div>
</div>
Now i want to update my database base on checkbox value.
For example if say i load checkbox 1 as checked from database and now it's unchecked i need to update it in database.
This code i can get all the current status of checkbox but i don't know previous values of this. So it hard update statue of current values and add new status in database,
$chks = array('multicolor','resizable','showRuler','namesNumbersEnabled');
foreach ($chks as $chk) {
$product->setAttribute($chk, (Input::has($chk)) ? true : false);
}
This is my json object save in data column
{"user_token":"ad48c412-3866-4ac9-adf6-3328911ae46c",
"order_info":
{"order_id":"CGC12345678","company_id":32,"price":1000.5,"currency":"MYR",
"products":[
{"type":"HR_ECLAIM","name":"HREClaim","is_fixed_price":true,"price":500.5,"currency":"MYR"},
{"type":"HR_ELEAVE","name":"HRELeave","is_fixed_price":true,"price":500,"currency":"MYR"}
],
"total_invoices":200,"total_staffs":80},"url":"https://drive.google.com/open?id=1Is6QsnuMLu9ZIpqeEzR2O2Ve1wUyF92aVCg55kWsOgc"}
i load [order_info][products][type] as checked products in while i load all the products from env file. I only need to save checked check box products in db.
Can someone helps me?
This is the complete working solution i done for my question!
public function edit($id, $attributes){
$orders = (new Agos())->load($id);
$json = $orders->data;
$json = json_decode($json);
$checkedit= $attributes['check_list'];
if (is_array($checkedit) || is_object($checkedit))
{
foreach($checkedit as $chked1){
$exists = false;
foreach($json->products as $key => $val)
{
// update if products exists
if($val->type == $chked1) {
$val->status = 'true';
$exists = true;
}
if(array_key_exists('status', $val)) {}
else{ $val->status = 'false';}
}
if($chked1 == 'FIN_REPORTING')
{
$name = 'Finance reporting & book keeping';
}
elseif ($chked1 == 'FIN_ADVISORY')
{
$name = 'Finance Advisory';
}
elseif ($chked1 == 'PAYROLL_HRDB')
{
$name = 'PAYROLL_HRDB';
}
elseif ($chked1 == 'HR_ELEAVE')
{
$name = 'HR E-Leave';
}
else
{
$name = 'HR E-Claim';
}
//if products not exists add new products
if(!$exists) {
$newproduct = new \stdClass();
$newproduct->type = $chked1;
$newproduct->name = $name;
$newproduct->is_fixed_price = false;
$newproduct->currency = "MYR";
$newproduct->status = "true";
array_push($json->products, $newproduct);
}
}
}
//remove all products that have status = false
foreach($json->products as $index => $product) {
if ( $product->status == "false") {
unset($json->products[$index]);
}
}
$json->products = array_values($json->products);
json_encode($json, JSON_PRETTY_PRINT);
//remove status element from products
foreach($json->products as $index => $product) {
unset($product->status);
}
$json->products = array_values($json->products);
json_encode($json, JSON_PRETTY_PRINT);
$json->google_drive_url= $attributes['data'];
$json->remark= $attributes['remark'];
$json->status= $attributes['status'];
$json->total_invoices= $attributes['total_invoices'];
$json->total_staffs= $attributes['total_staffs'];
$json1 = json_encode($json);
$status = $attributes['status'];
$total_price = str_replace(',','', $attributes['total_price']);
DB::table('orders')
->where('id', $id)
->update(['data' => $json1,'status' => $status, 'price' => $total_price]);
}

How to combine two SQL tables in codeigniter without using SQL queries?

Here is my codes,
//FROM MY CONTROLLER
$companies = $this->Uploads_model->getallcompanies();
$general = $this->Uploads_model->getallcontract();
$this->data['companieslist'] = $companies;
$this->data['uploads'] = $general;
$this->render('contracts/index_view');
// MY VIEW
foreach($companieslist as $company){
$general_c[] = $company->company_id;
$general_c[] = $company->company_name;
}
foreach ( $uploads as $key => $con ) {
?>
<tr>
<td class="center">
<label class="pos-rel">
<input type="checkbox" class="ace"/>
<span class="lbl"></span>
</label>
</td>
<td>
<a href="#">
<?php
if($con->Company_id == $general_c[$company_id]){ // MY QUESTION IS HERE
echo $con->Company_name;
}
?>
</a>
</td>
So, am working on this web app where am supposed to display in table all contract files followed with company owned this contract.
I have two tables in my Database as follow Companies_tbl and contract_tbl.
I have Company_id as a foreign key in contract_tbl.
Create a custom function to filter your contracts based on Company_id
function getContractsForId($contracts,$Company_id) {
return array_filter($contracts,function(){
return $contracts->Company_id === $Company_id;
});
}
template loop:
foreach( getContractsForId($uploads,$Company_id) as $key => $con) {
//...html...
//remove the if
}
You are not building the array of companies the right way.
foreach($companieslist as $company){
$general_c[] = $company->company_id;
$general_c[] = $company->company_name;
}
After you looped once, the $general_c array will look like this:
$general_c = [
0 => 1, //company id
1 => 'Company name'
]
After the second time:
$general_c = [
0 => 1, //company id
1 => 'Company name',
2 => 2, //company id
3 => 'Company name 2'
]
What you want is the following:
foreach($companieslist as $company){
$general_c[$company->company_id] = $company->company_name;
}
And below:
<?php
if($general_c[$con->Company_id]) {
echo $general_c[$con->Company_id];
} ?>
This will let you output the company name based on ID.
But i suggest you do a MySQL join in your model. Add something like this to your Uploads_model:
function getContractsWithCompany() {
$query = $this->db->select('*')
->from('contract_tbl')
->join('Companies_tbl', 'Companies_tbl.id = contract_tbl.Company_id')
->get();
return $query->result();
}
You need first to group files by Company_id then list the specific company files
$companies = $this->Uploads_model->getallcompanies();
$general = $this->Uploads_model->getallcontract();
$this->data['companieslist'] = $companies;
$this->data['uploads'] = array();
//group file list by Company_id
foreach ($general as $key => $file) {
if(!isset($this->data['uploads'][$file->Company_id ]))
$this->data['uploads'][$file->Company_id] = array();
$this->data['uploads'][$file->Company_id][] = $file;
}
// in your view
foreach($companieslist as $company){
$general_c[] = $company->company_id;
$general_c[] = $company->company_name;
if(isset($uploads[$company->company_id])) {
foreach ( $uploads[$company->company_id] as $key => $con ) {
?>
<tr>
<td class="center">
<label class="pos-rel">
<input type="checkbox" class="ace"/>
<span class="lbl"></span>
</label>
</td>
<td>
<?=$company->company_name?>
</td>
</tr>
<!-- and the rest of logic -->
<?php
}
}
}

Multiple Insert with dropdown codeigntier

I have3 table with name frm_data_aset,frm_monitor,frm_lokasi
I want if I insert on frm_data_aset column monitor_aset with dropdown from tabel monitor and lokasi from tabel lokasi. on table monitor column lokasi updated with data same at I insert from tabel data_Aset
this my structure :
enter image description here
enter image description here
now I get error :
Unknown column 'frm_monitor' in 'where clause'
UPDATE frm_monitor SET lokasi_monitor = '123' WHERE frm_monitor IS NULL
this my controller :
{
$this->_rules();
if ($this->form_validation->run() == FALSE) {
$this->create();
} else {
$data = array(
'lokasi_aset' => $this->input->post('lokasi_aset',TRUE),
'monitor_aset' => $this->input->post('monitor_aset',TRUE),
);
$id= $this->input->post('kd_monitor', TRUE);
$data = array(
'lokasi_monitor' => $this->input->post('lokasi_aset'),
);
$this->M_monitor->update_lokasi($id,$data);
$this->M_data_aset->insert($data);
redirect(site_url('data_aset'));
}
}
this my model M_monitor
function update_lokasi($id,$data){
$this->db->where('frm_monitor', $id);
$this->db->update('frm_monitor', $data);
}
and this my dropdown monitor at form insert data_aset
<option value="0">Pilih Monitor</option>
<?php
$monitor = $this->db->get('frm_monitor')->result();
foreach ($monitor as $row){
echo "<option value='$row->kd_monitor' ";
echo $row->kd_monitor==$monitor_aset?'selected':'';
echo ">". strtoupper($row->kd_monitor)."</option>";
}
?>
try changing your model query as like this
function update_lokasi($id,$data){
$this->db->where('id_monitor', $id);
$this->db->update('frm_monitor', $data);
}
Before that make sure that the post for 'kd_monitor' in the controller is not null
You should rename the $data variable being passed to $this->M_monitor->update_lokasi() because it will overwrite $data that is going to be passed to $this->M_data_aset->insert() with only 'lokasi_monitor' array on it. Or even better try rename both $data to prevent confusion.
Modify your controller :
{
$this->_rules();
if ($this->form_validation->run() == FALSE) {
$this->create();
} else {
$data_aset = array(
'lokasi_aset' => $this->input->post('lokasi_aset',TRUE),
'monitor_aset' => $this->input->post('monitor_aset',TRUE),
);
$id = $this->input->post('kd_monitor', TRUE);
$data_monitor = array(
'lokasi_monitor' => $this->input->post('lokasi_aset'),
);
$this->M_monitor->update_lokasi($id,$data_monitor);
$this->M_data_aset->insert($data_aset);
redirect(site_url('data_aset'));
}
}
And change 'frm_monitor' to 'kd_monitor' on the conditional query :
function update_lokasi($id,$data){
$this->db->where('kd_monitor', $id);
$this->db->update('frm_monitor', $data);
}

Add fields in laravel dynamically and unlimited

I have part of my website where users or admins can add restaurant list (is really like posts, just different naming)
There is some fixed inputs such as (title, description and map) I also need a part where users/admins can add restaurants menu this options is obviously can be different for each restaurant as their menu is a short list or long list.
So what I need is like + button where people can add fields and named their menu items with another field for the price of each item.
So my question is how to achieve this option?
What do I have at the moment?
Restaurant migrate:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRestaurantsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('restaurants', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->unique();
$table->string('slug')->unique();
$table->string('description')->nullable();
$table->string('image')->nullable();
$table->string('menu')->nullable();
$table->string('address')->nullable();
$table->integer('worktimes_id')->unsigned();
$table->integer('workday_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->string('verified')->default(0);
$table->string('status')->default(0);
$table->timestamps();
});
Schema::table('restaurants', function($table) {
$table->foreign('worktimes_id')->references('id')->on('worktimes');
$table->foreign('workday_id')->references('id')->on('workdays');
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('restaurants');
}
}
That's all, I still didn't create CRUD controller for restaurant because I'm holding for this option and your opinions.
Thanks.
UPDATE
STORE METHOD:
public function store(Request $request)
{
//Validating title and body field
$this->validate($request, array(
'title'=>'required|max:225',
'slug' =>'required|max:255',
'image' =>'sometimes|image',
'description' => 'required|max:100000',
'address' => 'sometimes|max:500',
'user_id' => 'required|numeric',
'verified' => 'sometimes',
'status' => 'required|numeric',
));
$restaurant = new Restaurant;
$restaurant->title = $request->input('title');
$restaurant->slug = $request->input('slug');
$restaurant->description = $request->input('description');
$restaurant->address = $request->input('address');
$restaurant->user_id = $request->input('user_id');
$restaurant->verified = $request->input('verified');
$restaurant->status = $request->input('status');
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'restaurant' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = public_path('images/');
$request->file('image')->move($location, $filename);
$restaurant->image = $filename;
}
// menu
$newArray = array();
$menuArray = $request->custom_menu; //Contains an array of Menu Values
$priceArray = $request->custom_price; //Contains an array of Price Values
//Creating new array with ARRAY KEY : MENU VALUES and ARRAY VALUE: PRICE VALUES
foreach ($menuArray as $key => $singleMenu) {
$newArray[$singleMenu] = $priceArray[$key];
}
//Output : array("Menu01" => "Price01", "Menu02" => "Price 02", "Menu03" => "Price 04", "Menu04" => "Price 05")
//Converting array to json format to store in your table row 'custom_menu_price'
$jsonFormatData = json_encode($newArray);
//Output like: {"Menu01":"Price01","Menu02":"Price 02","Menu03":"Price 04","Menu04":"Price 05"}
// Save in DB
//
//
//
// To retrieve back from DB to MENU and PRICE values as ARRAY
$CustomArray = json_decode($jsonFormatData, TRUE);
foreach ($CustomArray as $menu => $price) {
echo "Menu:".$menu."<br>";
echo "Price:".$price."<br>";
}
// menu
$restaurant->save();
$restaurant->workdays()->sync($request->workdays, false);
$restaurant->worktimes()->sync($request->worktimes, false);
//Display a successful message upon save
Session::flash('flash_message', 'Restaurant, '. $restaurant->title.' created');
return redirect()->route('restaurants.index');
What you can do is
1) add another one table row for custom_menu_price in your migration file
$table->string('custom_menu_price')->nullable();
2) Modify your form
<form method="POST" action="{{ ...... }}">
{{ csrf_field() }}
//I'm Looping the input fields 5 times here
#for($i=0; $i<5; $i++)
Enter Menu {{ $i }} : <input type="text" name="custom_menu[]"> //**Assign name as ARRAY
Enter Price {{ $i }} : <input type="text" name="custom_price[]"> //**Assign name as ARRAY
<br><br>
#endfor
<input type="submit" name="submit">
</form>
3) In your controller
public function store(Request $request) {
//Validating title and body field
$this->validate($request, array(
'title'=>'required|max:225',
'slug' =>'required|max:255',
'image' =>'sometimes|image',
'description' => 'required|max:100000',
'address' => 'sometimes|max:500',
'user_id' => 'required|numeric',
'verified' => 'sometimes',
'status' => 'required|numeric',
));
$restaurant = new Restaurant;
$restaurant->title = $request->input('title');
$restaurant->slug = $request->input('slug');
$restaurant->description = $request->input('description');
$restaurant->address = $request->input('address');
$restaurant->user_id = $request->input('user_id');
$restaurant->verified = $request->input('verified');
$restaurant->status = $request->input('status');
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'restaurant' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = public_path('images/');
$request->file('image')->move($location, $filename);
$restaurant->image = $filename;
}
// menu
$newArray = array();
$menuArray = $request->custom_menu; //Contains an array of Menu Values
$priceArray = $request->custom_price; //Contains an array of Price Values
//Creating new array with ARRAY KEY : MENU VALUES and ARRAY VALUE: PRICE VALUES
foreach ($menuArray as $key => $singleMenu) {
$newArray[$singleMenu] = $priceArray[$key];
}
//Output : array("Menu01" => "Price01", "Menu02" => "Price 02", "Menu03" => "Price 04", "Menu04" => "Price 05")
//Converting array to json format to store in your table row 'custom_menu_price'
$jsonFormatData = json_encode($newArray);
//Output like: {"Menu01":"Price01","Menu02":"Price 02","Menu03":"Price 04","Menu04":"Price 05"}
// Save in DB
$restaurant->custom_menu_price = $jsonFormatData;
// menu
$restaurant->save();
$restaurant->workdays()->sync($request->workdays, false);
$restaurant->worktimes()->sync($request->worktimes, false);
//Display a successful message upon save
Session::flash('flash_message', 'Restaurant, '. $restaurant->title.' created');
return redirect()->route('restaurants.index');
}
inside your front.restaurantshow view:
#php
// To retrieve back from DB to MENU and PRICE values as ARRAY
$CustomArray = json_decode($restaurant->custom_menu_price, TRUE);
#endphp
#foreach ($CustomArray as $menu => $price)
Menu Name: {{ $menu }} <br>
Menu Price: {{ $price }} <br><br>
#endforeach
Hope it makes sense.

Categories