Hi All,
I'm new to Laravel, so if there is something obvious that I'm missing, I do apologize. I'm hacking away at a custom CRM solution and encountering an issue when displaying a single record in a view. What is happening is that when Record ID 1 is displayed inside of the view, everything behaves as I would expect, only that record is returned and displayed. However, when any record above Record ID 1 is attempted to be viewed, for example, Record ID 3, both Record ID 1 and Record ID 3 are returned as a collection. Below is the code that I'm using
Route:
// Contact Classifications
Route::prefix('contact-classification')->controller(CrmClassificationController::class)->group(function () {
Route::get('', 'index')->name('settings.system-fields.contact-classification.index');
Route::post('', 'store')->name('settings.system-fields.contact-classification.store');
Route::get('{crm_classification}', 'show')->name('settings.system-fields.contact-classification.show');
});
CrmClassificationController::show
public function show(CrmClassification $crm_classification)
{
// dd($crm_classification);
$crm_collection = CrmClassification::find($crm_classification)->first();
//dd($crm_collection);
return view('settings.system-fields.field-details', [
'field_name' => 'Contact Classification',
'field_view' => 'settings.system-fields.contact-classification.index',
'field_value' => $crm_collection,
]);
}
When I dd($crm_classification), I'm seeing the correct ID being returned. When I dd($crm_collection), is when I see that multiple records are being returned.
I've tried the following so far:
Changing:
$crm_collection = CrmClassification::find($crm_classification)->first();
to
$crm_collection = CrmClassification::find($crm_classification)->last();
This technically works, but I'm afraid that this is not a long term solution and that the original method should be the proper solution.
I've also tried changing
'field_value' => $crm_collection,
to
'field_value' => collect($crm_collection),
but that does not appear to change the outcome.
I'm interested in whatever solutions this community can provide.
Thanks!
Marc