Hi i want to know that when $snake_attribute is false and we have write a accessor for like Parent_id that will be getParentIdAttribute() then why this fuction does not get called for such records where parent_id is null. i mean if the 1st record in DB have the parent_id 5 then accessor will be executed but if parent_id holds null then accessor is not called and returned null.
however if snake_case is true then it called for both cases NULL and Values case.
To define an accessor, create a getFooAttribute method on your model where Foo is the "studly" cased name of the column you wish to access. In this example, we'll define an accessor for the first_name attribute. The accessor will automatically be called by Eloquent when attempting to retrieve the value of the first_name attribute:
By:Xtreem Solution
Thanks and yes you are right but i dont want to retrieve the attribute, i just want to fetch the collection and then send it back to api response in json formate.
when snak_attribute is true then it work perfectly.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community