D
D
Dmitry2019-05-17 10:23:27
Laravel
Dmitry, 2019-05-17 10:23:27

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');
});

There is a controller
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']),
        ]);
    }
}

in which I redefined action register
When sending a request POSTfrom the registration page dd($request);in the controller, it does not work.
Where is the mistake?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
metallix, 2019-05-17
@ddimonn8080

Doesn't work because the method register(Request $request);is already defined in the trait RegistersUsers;.
see line - in your controller. use RegistersUsers;

J
jazzus, 2019-05-17
@jazzus

Try instead of routes and clear cache php artisan route:clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question