Skip to content

Instantly share code, notes, and snippets.

@egulhan
Last active April 4, 2019 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egulhan/6e874a88b96e4ba0c17d0d120ab62bd4 to your computer and use it in GitHub Desktop.
Save egulhan/6e874a88b96e4ba0c17d0d120ab62bd4 to your computer and use it in GitHub Desktop.
How to call trait's construct method in PHP
<?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