knath632
knath632

Reputation: 19

Get Data in edit_customer.blade.php file

I am new to Laravel and I am using Laravel 8 for my project.

In edit_customer.blade.php I need to show individual data.

IN the Controller file I have used the following code:

function showCustData($cust_id ){

    $get_cust_data = AddCustomer::where('customer_id', $cust_id)->get();
    
    return view('edit_customer',['currentcustomer'=>$get_cust_data]);   
    }

and in the view file, I am getting the following result by using {{$currentcustomer}}:

[
  {
    "customer_id": 1,
    "current_admin_id": 0,
    "customer_type": "customer_type_purchase",
    "customer_name": "Sadhan Basu",
    "customer_gst": "12345789GST",
    "customer_account_number": "Ac1234567/89",
    "customer_stat_ut": "234234234",
    "customer_currency": "INR - Indian rupee",
    "customer_phone": "9874561230",
    "customer_email": "[email protected]",
    "customer_country": "countryname",
    "customer_state": "ggg",
    "customer_city": "oooo",
    "customer_address": "Some Address here",
    "customer_proser": "product sold",
    "customer_product_hsn": "[email protected]",
    "customer_product_sac": "fwsff",
    "reg_date": "2021-03-20 18:32:08"
  }
]

How to get these data individually?

I have tried following codes but getting error like those fields are missing:

1> {{$currentcustomer["customer_id"]}}
2> {{$currentcustomer->customer_id}} 

Upvotes: 1

Views: 124

Answers (3)

abdo jawish
abdo jawish

Reputation: 9

Just Use @foreach in The View and You Will Be Able To Access Your Array Object

@foreach ($users as $user)
<p>This is user {{ $user->id }}</p>

@endforeach

and you could review the laravel documentation laravel blade documentation

Upvotes: 0

Al-Amin Sarker
Al-Amin Sarker

Reputation: 508

You want to show individual data, It's very easy to retrieve data from database using first() method. You may use this method in your controller showCustData() method.

Controller method

function showCustData($cust_id ) {
    $currentcustomer = AddCustomer::where('customer_id', $cust_id)->first();
    return view('edit_customer', compact('currentcustomer'));   
}

Blade view

{{ $currentcustomer->customer_id }}

Upvotes: 2

A.A Noman
A.A Noman

Reputation: 5270

You have to use like this

function showCustData($cust_id ){

    $get_cust_data = AddCustomer::where('customer_id', $cust_id)->first();

    return view('edit_customer',compact('get_cust_data'));   
}

And in your view file just use like this

{{ $get_cust_data->customer_id }} or {{ $get_cust_data->customer_type }} or ...

Upvotes: 2

Related Questions