Answer the question
In order to leave comments, you need to log in
Why is action not firing in Laravel?
Hello. There is a route
routes/web.php
Route::group(['middleware' => 'guest'], function(){
Route::get('/register', 'Auth\[email protected]');
Route::post('/register', 'Auth\[email protected]');
});
Route::get('/{path?}', function () {
return view('home');
});
app/Http/Controllers/Auth/RegisterController.php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest');
}
public function register(Request $request)
{
dd($request);
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
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'],
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
register
POST
from the registration page dd($request);
in the controller, it does not work. Answer the question
In order to leave comments, you need to log in
Doesn't work because the method register(Request $request);
is already defined in the trait RegistersUsers;
.
see line - in your controller. use RegistersUsers;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question