Advertisement
Guest User

srp example

a guest
Nov 19th, 2020
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UserCreateRequest {
  2.  
  3.         public function rules(): array {
  4.             return [
  5.            'first_name' => 'required',
  6.            'last_name' => 'required',
  7.            'email' => 'required|email|unique:users',
  8.            'phone' => 'nullable'
  9.        ];
  10.         }
  11.  
  12.     protected function failedValidation(Validator $validator)
  13.     {
  14.                 return back()->withErrors($validator)->withInput();
  15.     }
  16. }
  17.  
  18. class UserController extends Controller {
  19.  
  20.     public function store(UserCreateRequest $request, UserService $userService)
  21.     {
  22.        $userService->createUserFromRequest($request);
  23.        return redirect()->route('login');
  24.     }
  25. }
  26.  
  27. class UserService {
  28.  
  29.         public function createUserFromRequest(Request $request) {
  30.                 // to do something
  31.         }
  32. }
Advertisement
RAW Paste Data Copied
Advertisement