Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Last active August 29, 2015 13:57
Show Gist options
  • Save dadamssg/9776040 to your computer and use it in GitHub Desktop.
Save dadamssg/9776040 to your computer and use it in GitHub Desktop.
<?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