LoginSignup
4

More than 5 years have passed since last update.

laravel4でモデルクラスのコンストラクタを拡張したいとき

Last updated at Posted at 2013-12-11

書き方

MyModel.php
   public function __construct($attributes = array(), $exists = false)
   {
      parent::__construct($attributes, $exists);

      // ここに自分のコードを書く
   } 

補足

継承する実際の処理は
https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Eloquent/Model.php
の下記の部分。

Model.php
public function newInstance($attributes = array(), $exists = false)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4