Skip to content

Instantly share code, notes, and snippets.

@Vercoutere
Last active September 16, 2015 09:38
Show Gist options
  • Save Vercoutere/f899468723ac82ad39f3 to your computer and use it in GitHub Desktop.
Save Vercoutere/f899468723ac82ad39f3 to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class One extends Model {
public function getIdAttribute($value) {
return 'This is an obfuscated id: ' . $value;
}
// one.id = 5, one.two_id = 3
// $result = App\One::find(5);
// dd($result)->id; returns "This is an obfuscated id: 5"
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Two extends Model {
public function relation() {
return $this->BelongsTo('App\RelatedModel');
}
// two.id = 3
// $result = App\Two::find(3)->with('relation');
// dd($result->relation); is null, where an instance of App\One was expected.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment