action = $action; $this->request = $request; $this->model = $asset_level; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(AssetLevel $asset_level, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $asset_level = $asset_level->create($attributes); return $asset_level; } public function update(AssetLevel $asset_level, array $request) { $attributes = $request; $asset_level->update($attributes); return $asset_level; } public function destroy(AssetLevel $asset_level, array $request) { $asset_level->delete(); return $asset_level; } public function copy(AssetLevel $asset_level, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $asset_level = $asset_level->replicate(); $asset_level->created_at = Carbon::now(); $asset_level->save(); return $asset_level; } for ($i = 1; $i <= $count; $i++) { $new = $asset_level->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $asset_level; } }