src/models/Page.php
public static function boot()
	{
		parent::boot();

		static::saving(function($page) {
			$page->plaintext = strip_tags($page->html);
			if (!$page->published_range) {
				$page->published_start = $page->published_end = null;
			}
			$page->title = $page->title ? $page->title : $page->name;
			$page->url   = strtolower($page->url);
		});
		static::saved(function($page) {
			if ($page->skipEvents) return;

			$PageModule    = App::make('PageModule');
			$modules       = $PageModule::where('page_id', $page->id)->get();
			$input_modules = Input::get('modules');

			$input_module_ids = array();
			foreach ($input_modules as $number=>$input_module) {
				// If there's only one module and it's blank, skip it.
				if (!$input_module['name'] && !$input_module['html'] && count($input_modules) == 1) continue;

				// Create a list of module IDs so we can delete the missing modules (which must have been deleted).
				if ($input_module['id']) $input_module_ids[] = $input_module['id'];

				// Grab the existing module if it exists.
				$module_existing = $modules->find($input_module['id']);
				$module          = ($module_existing) ? $module_existing : new $PageModule;

				// If the module exists, log its changes.
				$input_module['number'] = $number;
				if ($module_existing) {
					foreach (array('number', 'html', 'name') as $column) {
						if ($input_module[$column] != $module->$column) {
							$changes['Module ID#' . $module->id . ' ' . $column] = array(
								'old' => $module->$column,
								'new' => $input_module[$column]
							);
						}
					}
				}

				// Save that bad boy.
				$module->page_id = $page->id;
				$module->number  = $number;
				$module->name    = $input_module['name'];
				$module->html    = $input_module['html'];
				$module->save();
			}

			// Delete the deleted modules.
			foreach ($modules as $module) {
				if (!in_array($module->id, $input_module_ids)) {
					$module->delete();
				}
			}
		});
	}
public static function boot()
	{
		parent::boot();

		static::saving(function($page) {
			$page->plaintext = strip_tags($page->html);
			if (!$page->published_range) {
				$page->published_start = $page->published_end = null;
			}
			$page->title = $page->title ? $page->title : $page->name;
			$page->url   = strtolower($page->url);
		});
		static::saved(function($page) {
			if ($page->skipEvents) return;

			$PageModule    = App::make('PageModule');
			$modules       = $PageModule::where('page_id', $page->id)->get();
			$input_modules = Input::get('modules');

			$input_module_ids = array();
			foreach ($input_modules as $number=>$input_module) {
				// If there's only one module and it's blank, skip it.
				if (!$input_module['name'] && !$input_module['html'] && count($input_modules) == 1) continue;

				// Create a list of module IDs so we can delete the missing modules (which must have been deleted).
				if ($input_module['id']) $input_module_ids[] = $input_module['id'];

				// Grab the existing module if it exists.
				$module_existing = $modules->find($input_module['id']);
				$module          = ($module_existing) ? $module_existing : new $PageModule;

				// If the module exists, log its changes.
				$input_module['number'] = $number;
				if ($module_existing) {
					foreach (array('number', 'html', 'name') as $column) {
						if ($input_module[$column] != $module->$column) {
							$changes['Module ID#' . $module->id . ' ' . $column] = array(
								'old' => $module->$column,
								'new' => $input_module[$column]
							);
						}
					}
				}

				// Save that bad boy.
				$module->page_id = $page->id;
				$module->number  = $number;
				$module->name    = $input_module['name'];
				$module->html    = $input_module['html'];
				$module->save();
			}

			// Delete the deleted modules.
			foreach ($modules as $module) {
				if (!in_array($module->id, $input_module_ids)) {
					$module->delete();
				}
			}
		});
	}
/////////////////////////////////////////////