Last active
April 4, 2019 11:23
-
-
Save egulhan/6e874a88b96e4ba0c17d0d120ab62bd4 to your computer and use it in GitHub Desktop.
How to call trait's construct method in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\Campaign; | |
use Illuminate\Database\Eloquent\Model; | |
use App\Classes\Traits\SetModelConnectionToSlave; | |
class CampaignDiscount extends Model | |
{ | |
use SetModelConnectionToSlave { | |
SetModelConnectionToSlave::__construct as private __setModelConnectionToSlaveConstruct; | |
} | |
public function __construct() | |
{ | |
parent::__construct(); | |
/* ... do other stuff here ... */ | |
// call trait's __constructor | |
$this->__setModelConnectionToSlaveConstruct(); | |
} | |
/* ...*/ | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment