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