1
public $tracksSystemDir;
public $contentSystemDir;


public function __construct(array $attributes = [])
{
    parent::__construct($attributes);

    // setup system directory paths
    $this->tracksSystemDir = public_path() . '/users/' . $this->reference . '/tracks/';
    $this->contentSystemDir = public_path() . '/users/' . $this->reference . '/content/';
}

when i try to user $this->tracksSystemDir it returns empty, in fact User object returns empty

User {#420 ▼
  #guarded: array:1 [▶]
  #dates: array:1 [▶]
  #hidden: array:2 [▶]
  +tracksSystemDir: "/home/vagrant/Code/9mmradio/public/storage/users//tracks/"
  +contentSystemDir: "/home/vagrant/Code/9mmradio/public/storage/users//content/"
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: []
  #original: []
  #relations: []
  #visible: []
  #appends: []
  #fillable: []
  #dateFormat: null
  #casts: []
  #touches: []
  #observables: []
  #with: []
  +exists: false
  +wasRecentlyCreated: false
  #forceDeleting: false
 }

This is returned user object when i dump the variable. i have googled about this and i found nothing and i went through the documentation couple of time and found nothing regarding too. So any help with this one is greatly appreciated :)

1
  • Do you just want to add two properties to the user model?? Commented Dec 30, 2016 at 17:18

1 Answer 1

1

If you just want to add two properties to your user model, you can use Accessors as below:

public function getTracksSystemDirAttribute()
{
    return public_path() . '/users/' . $this->reference . '/tracks/';
}

then you can use it by saying:

$user = User::find(1);
$user->tracks_system_dir;

And the same can be done for any other property.

Note that the you should follow the naming as in the example. More on that in laravel documentation : Accessors

Sign up to request clarification or add additional context in comments.

1 Comment

i have done it multiple times in the same project, bad memory :D. anyway thanks for reminding it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.