Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What are the problem?

laravel fill() メソッドの定義場所 個人メモ


  • 各モデルクラスでモデルに配列を追加するときに使用するfill()メソッドの記載場所をメモ的にまとめておく


  • アプリ名ディレクトリ/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.phpの中に記載されている。
  • 下記に定義部分を抜粋して記載する。

     * Fill the model with an array of attributes.
     * @param  array  $attributes
     * @return $this
     * @throws \Illuminate\Database\Eloquent\MassAssignmentException
    public function fill(array $attributes)
        $totallyGuarded = $this->totallyGuarded();
        foreach ($this->fillableFromArray($attributes) as $key => $value) {
            $key = $this->removeTableFromKey($key);
            // The developers may choose to place some attributes in the "fillable" array
            // which means only those attributes may be set through mass assignment to
            // the model, and all others will just get ignored for security reasons.
            if ($this->isFillable($key)) {
                $this->setAttribute($key, $value);
            } elseif ($totallyGuarded) {
                throw new MassAssignmentException(sprintf(
                    'Add [%s] to fillable property to allow mass assignment on [%s].',
                    $key, get_class($this)
        return $this;
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?