In my Laravel app, I have A model that defines a relationship like:
public function vitalCategories()
{
return $this->belongsToMany(
'App\Models\Diagonals\VitalLabelCategory',
'vitalLabelCategoryMap',
'vitalLabelId',
'vitalLabelCategoryId');
}
When I query a record like below, I expect the relation to be available with the variable name vitalCategories
$vitalLabel = VitalLabel::where('label', 'confirmation')->with(['subscribers','vitalCategories','vitals'])->first();
return json_encode($vitalLabel);
However, the above query produces the relation with the variable name 'vital_categories' like this:
How can I make laravel stop changing the case of my variable for the relation to snake case?
Just for grins, I also tried:
$vitalLabel = VitalLabel::where('label', 'confirmation')->with(['subscribers','vitalCategories','vitals'])->first();
$vitalLabel->load('vitalCategories');
$vitalLabel->vitalCategories = $vitalLabel->vitalCategories() ;
return json_encode($vitalLabel);
which failed to see the related models:
so then I tried:
$vitalLabel = VitalLabel::where('label', 'confirmation')->with(['subscribers','vitalCategories','vitals'])->first();
$vitalLabel->load('vitalCategories');
$vitalLabel->vitalCategories = $vitalLabel->vital_categories;
return json_encode($vitalLabel);
which also failed to see the related models: