Created
December 18, 2012 20:59
-
-
Save Sigmus/4331921 to your computer and use it in GitHub Desktop.
Laravel: modelo temporário
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 | |
// 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