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