/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('shipment_carriers_countries', function (Blueprint $table) {
         $table->bigInteger('carrier_id')->unsigned();
         $table->bigInteger('country_id')->unsigned();
         $table->foreign('carrier_id')->references('id')->on(Carrier::getTableName())->onDelete('cascade');
         $table->foreign('country_id')->references('id')->on(Country::getTableName())->onDelete('cascade');
         $table->primary(['carrier_id', 'country_id']);
     });
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create(CarrierService::getTableName(), function (Blueprint $table) {
         $table->bigIncrements('id');
         $table->bigInteger('carrier_id')->unsigned();
         $table->string('name');
         $table->string('code');
         $table->string('description')->nullable();
         $table->tinyInteger('delivery_time')->default(1);
         $table->tinyInteger('status')->default(1);
         $table->timestamps();
         $table->index(['name']);
         $table->index(['carrier_id', 'code']);
         $table->foreign('carrier_id')->references('id')->on(Carrier::getTableName())->onDelete('cascade');
     });
 }
 public function __construct(App $app)
 {
     parent::__construct($app);
     $this->tableCarriers = Carrier::getTableName();
     $this->tableCountry = $this->getModel()->getTableName();
 }
 public function allWithCountry(Country $country)
 {
     $query = $this->getModel()->newQuery()->select(Carrier::getTableName() . '.*')->join('shipment_carriers_countries', 'shipment_carriers_countries.carrier_id', '=', Carrier::getTableName() . '.id')->join(Country::getTableName(), 'shipment_carriers_countries.country_id', '=', Country::getTableName() . '.id')->where(Country::getTableName() . '.id', $country->id);
     $key = md5($query->toSql() . $country->id);
     return $this->cacheQueryBuilder($key, $query);
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     if (Schema::hasTable(Carrier::getTableName())) {
         Schema::drop(Carrier::getTableName());
     }
 }