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