Support the ongoing development of Laravel.io →
Input Database Eloquent

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();
	}
}
Last updated 3 years ago.
0

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

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

ekstro ekstro Joined 21 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.