Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Created February 19, 2016 19:03
Show Gist options
  • Save scrubmx/d21b58e6222e515a3bf7 to your computer and use it in GitHub Desktop.
Save scrubmx/d21b58e6222e515a3bf7 to your computer and use it in GitHub Desktop.
Making Eloquent models readonly
<?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