Created
April 12, 2016 15:37
-
-
Save kicco/200290f8623c21da25544c306a18884c to your computer and use it in GitHub Desktop.
Laravel ReadOnly Trait
This file contains hidden or 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; | |
Trait ReadOnly | |
{ | |
/** | |
* 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