$data = array(
'country_name' => $country_name,
'country_code' => $country_code);
DB::insert('countries', array_keys($data))
->values(array_values($data))
->execute();
// For Example $country = new Model_Country; $country->name = 'New Zealand'; $country->postcode = 12345; $country->save();
// For Example // Imagine New Zealand got id = 1 in your table $country = Model_Country::find(1); // Ah, gnarf postcode was wrong, so let's fix it $country->postcode = 23478; $country->save();
Model_Country::$primary_key = 'country_code';
Model_Country::$primary_key = 'id';
Model_Country::find_by_country_code('USA');
$countries = array(
array(
'country_code' => 'nl',
'country_name' => 'Netherlands'
),
array(
'country_code' => 'us',
'country_name' => 'United States'
),
// etc. 250 countries
);
$country = new Model_Country;
$country->data_array = $countries;
$country->save;
foreach ($countries as $data)
{
$country = new Model_Country;
$country->country_code = $data['country_code'];
$country->country_name = $data['country_name '];
$country->save;
}
foreach ($countries as $data)
{
$country = Model_Country::find_by_country_code($data['country_code']);
if ($country)
{
$country->country_name = $data['country_name '];
$country->save;
}
else
{
$country = new Model_Country;
$country->country_code = $data['country_code'];
$country->country_name = $data['country_name'];
$country->save;
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!