Created
February 19, 2016 19:03
Making Eloquent models readonly
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 ReadOnly extends Model | |
{ | |
/** | |
* Indicates if the model should be timestamped. | |
* | |
* @var bool | |
*/ | |
public $timestamps = false; | |
/** | |
* Don't save the model to the database. | |
* | |
* @param array $options | |
* @return bool | |
*/ | |
public function save(array $options = []) | |
{ | |
return false; | |
} | |
/** | |
* Don't update the model in the database. | |
* | |
* @param array $attributes | |
* @param array $options | |
* @return bool | |
*/ | |
public function update(array $attributes = [], array $options = []) | |
{ | |
return false; | |
} | |
/** | |
* Don't delete the model from the database. | |
* | |
* @return bool | |
*/ | |
public function delete() | |
{ | |
return false; | |
} | |
/** | |
* Don't destroy the models for the given IDs. | |
* | |
* @param array|int $ids | |
* @return int | |
*/ | |
public static function destroy($ids) | |
{ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment