Last active
September 16, 2015 09:38
-
-
Save Vercoutere/f899468723ac82ad39f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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