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