Last active
August 29, 2015 13:57
-
-
Save dadamssg/9776040 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 | |
class Person extends Eloquent | |
{ | |
protected $table = 'people'; | |
} | |
class ReadOnlyPerson extends Person | |
{ | |
public function save() | |
{ | |
throw new \Exception('You cannot save a read only model!'); // or no-op and just return true/false | |
} | |
} | |
$person = Person::find(1); | |
$person->firstName = 'David'; | |
$person->save(); // OK | |
$person = ReadOnlyPerson::find(1); // Eloquent queries will still work | |
$person->firstName = 'David'; | |
$person->save(); // throws exception | |
// OR | |
class Person extends Eloquent | |
{ | |
protected $table = 'people'; | |
public function save() | |
{ | |
if ($this->someProperty == 'someValue') { | |
throw new \Exception('You cannot save this model!'); // or no-op and just return true/false | |
} | |
return parent::save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment