如何在「管理商户ID」视图中显示全名而非商户ID
Alright, let's get this sorted out for you. Here's a step-by-step solution to replace the $merchantId display with the fullname from your database:
Step 1: Update the SubMerchantController to Fetch the Fullname
First, you need to retrieve the corresponding SubMerchant record from your database using the $merchantId parameter, then pass the fullname (or the entire model instance) to your view.
Assuming you have a method in your SubMerchantController that handles this view (like show() or edit()), update it like this:
public function show($merchantId) { // Fetch the SubMerchant record using the merchantId // Adjust the column name if your merchant ID field is named differently (e.g., id) $subMerchant = SubMerchant::where('merchantId', $merchantId)->firstOrFail(); // Pass both the merchantId (if you still need it elsewhere) and the subMerchant instance to the view return view('your-view-path-here', compact('merchantId', 'subMerchant')); }
Note: Replace your-view-path-here with the actual path to your view file (e.g., submerchants.manage).
Step 2: Modify the View to Display the Fullname
Now update your view code to replace $merchantId with the fullname from the fetched SubMerchant instance. I also fixed a missing closing tag on the <i> element to avoid frontend issues:
<div class="content-header-left col-md-6 col-12 mb-1"> <h3 class="content-header-title mb-0 font-14"> <a href="#"> <i class="close icon-arrow-left font-16 px-50 float-left"></i> </a> Manage <?php echo $subMerchant->fullname; ?> </h3> </div>
If you prefer using Blade syntax (since this looks like a Laravel project), you can write {{ $subMerchant->fullname }} instead of <?php echo ... ?> for cleaner code.
Quick Checks
- Make sure your
SubMerchantmodel has thefullnamefield included in its$fillableproperty (if you're using mass assignment) or that it's not guarded. - Verify that the
merchantIdparameter passed to the controller method matches the column name in your database table.
内容的提问来源于stack exchange,提问作者Alok Srivastava

