I have form with hours (for every weekdays) and want: insert, update or delete row. Is there a better way to do something like this?
$input = Input::except('_token');
foreach($input as $item)
{
$time = Hours::firstOrNew(array('ex_key' => $item['ex_key']));
if ($item['ex_hour'])
{
$time->ex_hour = $item['ex_hour'];
$time->save();
}
else
{
$time->forceDelete();
}
}
you can use transactions. if one fails, all fail and rollback. is that what you're looking for? http://laravel.com/docs/database#database-transactions
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community