/** @test */ public function it_stores_country() { $dbCountryRepository = new DbCountryRepository(); $countryModel = new Country(); $countryFillableKeys = $countryModel->getFillable(); $expectedCountryData = array_only(factory(Country::class, 'relationless')->make()->toArray(), $countryFillableKeys); $this->dontSeeInDatabase('countries', $expectedCountryData); $country = $dbCountryRepository->store($expectedCountryData); $this->assertNotFalse($country); $this->seeInDatabase('countries', $expectedCountryData); }
/** * Store a country. * * @param $data * @return Country|false */ public function store($data) { $country = new Country(array_only($data, $this->getModel()->getFillable())); return $country->save() ? $country : false; }
/** * Update the country of a company. * * @param Company $company * @param $countryId * * @return Company|false */ public function assignCountryById(Company $company, $countryId) { $country = Country::find($countryId); $company->country()->associate($country); return $company->save() ? $company : false; }