jeudi 6 février 2020

laravel How to change column name while using relation ships

i have following function in my notes controller ,which is working fine

public function getAllNotes($modelName, $modelID) {
    $modelNameCamelized = self::camelize($modelName);
    $modelClass = FTM::getClass("App\\Models\\" . $modelNameCamelized);
    $obj = $modelClass::with(['notes'])->find($modelID);

    if (!class_exists($modelClass)) {
        return response()->view('errors.404', [], 404);
    }
    if ($obj) {
        return $obj;
    }
}

the result from it is in json as below

{
 "PersonID": 3,
 "UserID": 14,
 "TitleID": 2,
 "is_participant": 1,
 "is_trainer": 1,
 "is_free_lancer": 0,
 "LastName": "Patel     ",
 "FirstName": "Rupesh",
 "NickName": null,
 "Email": "patel.rupesh.009@gmail.com",
 "Birthdate": "2018-10-30",
 "Age": 1,
 "Gender": "1",
 "is_dnd": "1",
 "Note": "",
 "JobID": null,
 "ProfessionID": 1,
 "DepartmentID": 9,
 "InternalID": "",
 "OrganizationID": 24,
 "SalutationID": 1,
 "notes":[],//array of notes
 }

i just want to change the name of node 'notes' to 'something_other_name' using query or any other laravel way ,is it possible to do so? or am i doing something wrong? thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire