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