public function addCountry(Country $country) { $countCountries = $this->getCountriesBy(Country::getTableName() . '.code', $country->code)->count(); if ($countCountries == 0) { $this->getCountries()->attach($country->id); } $this->flushCacheByTags('CarriersCountries'); }
/** * 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']); }); }
/** * Reverse the migrations. * * @return void */ public function down() { if (Schema::hasTable(Country::getTableName())) { Schema::drop(Country::getTableName()); } }