我正在工作台环境中开发一个包。我有一个模型
<?php namespace Vendor\Webshop\Models;
use Vendor\Webshop\Models\Country as Country;
use Illuminate\Database\Eloquent\Model as Eloquent;
/**
* A catalog
*/
class Catalog extends Eloquent {
// Define the database
protected $table = 'catalogs';
// Mass assignment restriction
protected $guarded = array('id');
// Return the countries related to this catalog
public function countries() {
return $this->belongsToMany('Vendor\Webshop\Models\Country');
}
/**
* Returns whether to enforce the compability check or not
*/
public function getForceCompabilityTest() {
return $this->force_compability_check;
}
}
?>
我想知道我是否可以拥有像这样的自定义实例获取器
public function getDefaultCatalogs() {
return Catalog::where('is_default_catalog', '=', true)->get();
}}
在类本身内。这是可能的还是这些方法仅适用于具体实例,我可以像Catalog::getDefaultCatalogs()
从类外一样调用它们吗?