我只是通過laravel tutrorial去網上,我看到下面的模態編碼如下:瞭解在laravel型號靜態方法
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notice extends Model {
protected $fillable = [
'provider_id',
'infringing_title',
'infringing_link',
'original_link',
'original_description',
'template',
'content_removed'
];
public static function open(array $attributes) {
return new static($attributes);
}
public function useTemplate($template) {
$this->template = $template;
}
}
什麼,我想知道到底是什麼是利用以下被定義的方法:
public static function open(array $attributes) {
return new static($attributes);
}
我意識到它是一個靜態方法,但此行return new static($attributes);
特別是混淆了我。
我看到下面的方式使用方法:
$notice = Notice::open($date);
但我還是不太瞭解它的用法。有人可以解釋。