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