Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在edit_customer.blade.php文件中获取数据_Php_Laravel - Fatal编程技术网

在edit_customer.blade.php文件中获取数据

在edit_customer.blade.php文件中获取数据,php,laravel,Php,Laravel,我对Laravel是新手,我正在使用Laravel 8进行我的项目 在edit_customer.blade.php中,我需要显示单个数据 在控制器文件中,我使用了以下代码: function showCustData($cust_id ){ $get_cust_data = AddCustomer::where('customer_id', $cust_id)->get(); return view('edit_customer',['currentcusto

我对Laravel是新手,我正在使用Laravel 8进行我的项目

在edit_customer.blade.php中,我需要显示单个数据

在控制器文件中,我使用了以下代码:

function showCustData($cust_id ){

    $get_cust_data = AddCustomer::where('customer_id', $cust_id)->get();
    
    return view('edit_customer',['currentcustomer'=>$get_cust_data]);   
    }
在视图文件中,我使用{{$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": "abc@test.com",
    "customer_country": "countryname",
    "customer_state": "ggg",
    "customer_city": "oooo",
    "customer_address": "Some Address here",
    "customer_proser": "product sold",
    "customer_product_hsn": "ad@dsg.fwe",
    "customer_product_sac": "fwsff",
    "reg_date": "2021-03-20 18:32:08"
  }
]
如何单独获取这些数据

我尝试了以下代码,但出现错误,如缺少这些字段:

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

要显示单个数据,使用
first()
方法从数据库检索数据非常容易。您可以在
控制器
showCustData()
方法中使用此方法

控制器方法

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

{{ $currentcustomer->customer_id }}

要显示单个数据,使用
first()
方法从数据库检索数据非常容易。您可以在
控制器
showCustData()
方法中使用此方法

控制器方法

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

{{ $currentcustomer->customer_id }}

你必须像这样使用

function showCustData($cust_id ){

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

    return view('edit_customer',compact('get_cust_data'));   
}
{{ $get_cust_data->customer_id }} or {{ $get_cust_data->customer_type }} or ...
在您的视图文件中,只需这样使用

function showCustData($cust_id ){

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

    return view('edit_customer',compact('get_cust_data'));   
}
{{ $get_cust_data->customer_id }} or {{ $get_cust_data->customer_type }} or ...

你必须像这样使用

function showCustData($cust_id ){

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

    return view('edit_customer',compact('get_cust_data'));   
}
{{ $get_cust_data->customer_id }} or {{ $get_cust_data->customer_type }} or ...
在您的视图文件中,只需这样使用

function showCustData($cust_id ){

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

    return view('edit_customer',compact('get_cust_data'));   
}
{{ $get_cust_data->customer_id }} or {{ $get_cust_data->customer_type }} or ...

只要在视图中使用@foreach,您就可以访问您的数组对象

只要在视图中使用@foreach,您就可以访问您的数组对象

我已经尝试了该代码,它给了我以下错误:尝试读取字符串上的属性“customer\u id”(视图:E:\xampp\htdocs\saledoc\resources\views\edit\u customer.blade.php)更新我的答案。检查它。它显示以下错误:未定义的变量$currentcustomer(视图:E:\xampp\htdocs\saledoc\resources\views\edit\u customer.blade.php)$currentcustomer未定义使用
dd($currentcustomer)
检查它得到了错误,但向上投票。这真是太不公平了,我尝试过该代码,它给了我以下错误:尝试读取字符串上的属性“customer\u id”(视图:E:\xampp\htdocs\saledoc\resources\views\edit\u customer.blade.php)更新我的答案。检查它。它显示以下错误:未定义的变量$currentcustomer(视图:E:\xampp\htdocs\saledoc\resources\views\edit\u customer.blade.php)$currentcustomer未定义使用
dd($currentcustomer)
检查它得到了错误,但向上投票。这确实不公平方法
get()
会返回一个数组。如果要访问单个客户,请使用
first()
。在不更改方法的情况下,您应该能够使用
{{$currentcustomer[0]->customer\u id}
访问customer\u id}
非常感谢方法
get()
返回一个数组。如果要访问单个客户,请使用
first()
。在不更改方法的情况下,您应该能够使用
{{$currentcustomer[0]->customer\u id}
访问customer\u id,非常感谢。它正在工作。非常感谢。@knath632,如果它能工作,请接受其他开发者的帮助,他们将面对同样的问题。它正在工作。非常感谢。@knath632,如果它有效,请接受和帮助将面临相同问题的其他开发人员