samedi 25 août 2018

Eloquent where doesn't work after overwriting model constructor

I am trying to develop a web application using laravel 5.3 and came up with a problem couldn't solve so far.

Heres the Context.

I got a simple Laravel Model called 'Section' which implements a constructor as shown below;

public function __construct($title = null, array $attributes = array()){
        parent::__construct($attributes);
        try {
            \App\logic_model\system\internal\Logger::debug_dump("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            \App\logic_model\system\internal\Logger::debug_dump("create section ".$title);

            $this->title = $title;
            $this->save();

            return $this;
        } catch(\Exception $e){
            \App\logic_model\system\internal\Logger::dev_dump($e->getMessage());
            throw $e;
        }
}

Instance creation using the constructor seems to be working pretty well.

I wrote a function 'find_by_title' as shown below:

public static function find_by_title($title){
    $section = \App\logic_model\sections\Section::where("title", "=", $title)->first();
    return $section;
}

Here occurs the Problem (the unexpected behaviour): The Eloquent 'where' function seems to call my overloaded constructor instead of the default constructor.

My question is: Why is that? How to fix it?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2MukUZj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire