Framework: Camel case model relationship is returned as snake case property

Created on 19 May 2016  路  3Comments  路  Source: laravel/framework

How can i tell laravel to return the relationship results in same name as the relationship function?
ex. I have relationship called mediaItem and when i call $model->with('mediaItem') is is returned as {media_item: {}}. Is there a way that it is returned as {mediaItem:{}}?

Most helpful comment

@GrahamCampbell Isn't public static $snakeAttributes = false; attribute the solution to this?

ref: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Database/Eloquent/Model.php#L204

All 3 comments

No, sorry.

@GrahamCampbell Isn't public static $snakeAttributes = false; attribute the solution to this?

ref: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Database/Eloquent/Model.php#L204

@klimentLambevski you can solve this using:

Network.php

  public function pointsOfSale()
    {
        return $this->hasMany(PointOfSale::class);
    }

PointOfSale.php

 public function network()
    {
        return $this->belongsTo(Network::class, 'networkId');
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  路  3Comments

progmars picture progmars  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

felixsanz picture felixsanz  路  3Comments

PhiloNL picture PhiloNL  路  3Comments