ให้เปิดไฟล์ laravel\app\Http\Controllers\Auth\RegisterController.php ขึ้นมากจากนั้นเพิ่มโค๊ดด้านล่างนี้ต่อจากโค๊ด use Illuminate\Foundation\Auth\RegistersUsers;
1 2 3 |
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Auth\Events\Registered; |
และเพิ่ม Methods register
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * Override the register method * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); //The auto login code has been removed from here. // $this->guard()->login($user); return $this->registered($request, $user) ?: redirect($this->redirectPath()); } |
โค๊ดทั้งหมดก็จะประมาณนี้ครับ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
<?php namespace App\Http\Controllers\Auth; use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Auth\Events\Registered; class RegisterController extends Controller { /* |-------------------------------------------------------------------------- | Register Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users as well as their | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | */ use RegistersUsers; /** * Where to redirect users after registration. * * @var string */ protected $redirectTo = '/home'; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest'); } /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); } /** * Override the register method * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); //The auto login code has been removed from here. // $this->guard()->login($user); return $this->registered($request, $user) ?: redirect($this->redirectPath()); } } |
ป้ายกำกับ:laravel