Last active
August 29, 2015 14:06
-
-
Save tsolar/ea08c04908a957f0555f to your computer and use it in GitHub Desktop.
Base Model for Laravel 4
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 | |
use LaravelBook\Ardent\Ardent; // it can be Eloquent too | |
class BaseModel extends Ardent { | |
protected $_name; | |
public static function optionList($attribute = 'name') { | |
$model = static::getModel(); | |
$name = $model->_name; | |
$lists = $model::lists($attribute, 'id'); | |
return array('' => "Choose {$name}...") + $lists; | |
} | |
public static function optionsList($attribute = 'name') { | |
return static::optionList($attribute); | |
} | |
public static function optionListExcluding($excludes = array(), $attribute = 'name') { | |
$lists = static::optionList($attribute); | |
if (!empty($excludes)) { | |
foreach ($excludes as $id) { | |
if (isset($lists[$id])) { | |
unset($lists[$id]); | |
} | |
} | |
} | |
return $lists; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment