Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created December 18, 2012 20:59
Show Gist options
  • Save Sigmus/4331921 to your computer and use it in GitHub Desktop.
Save Sigmus/4331921 to your computer and use it in GitHub Desktop.
Laravel: modelo temporário
<?php
// Na tabela existe uma coluna booleano "temp" que é "true" por padrão.
Route::get('/admin/edicao/create', function() {
return Redirect::to('/admin/edicao/' . Edicao::createTemp()->id);
});
// E no modelo tem os seguintes métodos:
public static function createTemp() {
static::removeTemps();
return static::create(array());
}
public static function removeTemps() {
static::where_temp(1)->delete();
}
public function save() {
if ($this->exists) {
$this->temp = false;
}
return parent::save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment