K
K
Kyber_Ded2021-12-03 17:56:02
Laravel
Kyber_Ded, 2021-12-03 17:56:02

Why is it giving a 302 redirect?

Good evening everyone. I say right away. I'm learning from an unfinished project.
There is a form. Everything seems to be present, including @crsv

<form id="phys_form" class="rdj-validate-form" method="POST" autocomplete="off" novalidate="novalidate" action="{{ route('register.phys') }}">
    @csrf
    <input type="hidden" name="form_type" value="phys">

    @include('auth.partials.fio_block', ['firstname_ph' => __('Имя'), 'lastname_ph' => __('Фамилия'), 'fathername_ph' => __('Отчество')])

    <label class="field-text">
        <span class="field-text__input-wrap input-field">

            <label class="pineput-label">Город</label>

            <input class="pineput-input field-text__input{{ $errors->has('city') ? ' __rds_incorrect' : '' }}"
            type="text"
               -placeholder="Город"
               -title="Город"
                name="city"
                value="{{ old('city') }}"
                -data-rd_required3-inputmask
                -required
            >

            @if ($errors->has('city'))
            <span class="field-text__help-text __rds_red_color" role="alert">
                {{ $errors->first('city') }}
            </span>
            @endif
        </span>
    </label>

    @include('auth.partials.phone_n_email_block')

    @include('auth.partials.password_block', ['type' => 'phys'])

    @include('auth.partials.reg_n_agree_block', ['type' => 'phys'])

</form>


Not sent by Ajax. Routing is
Auth::routes(['verify' => true]);
Route::redirect('/home', '/');

Route::post('/register-phys', 'Auth\[email protected]')->name('register.phys');


61aa2f9e1651a865250300.png

Everything seems to go away, but the var_dump in the action does not work and a 302 redirect is returned. Moreover, on all requests of the post type

public function create(PhysRegisterRequest $request) {
        var_dump(123);exit;
        $user = User::create([
            'name' => $request->lastname .' '. $request->firstname .' '. $request->fathername,
            'phone' => $request->phone,
            'email' => $request->email,
            'role' => User::ROLE_PHYS,
            'password' => bcrypt($request->password),
        ]);

        $user->sendEmailVerificationNotification();

        UsersPhysProfile::create([
            'user_id' => $user->id,

            'company_identify' =>  $request->lastname .' '. $request->firstname .' '. $request->fathername,
            'lastname' => $request->lastname,
            'firstname' => $request->firstname,
            'fathername' => $request->fathername,

            'phone_number' => $request->phone,
            'city' => $request->city,

        ]);

        Auth::loginUsingId($user->id);

        return redirect('account');
    }


Explain to the Padawan why this is happening and how to improve the situation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
exezio, 2021-12-08
@Kyber_Ded

The redirect is most likely a PhysRegisterRequest, see the rules method in it. If some field sent by the form is invalid, then a redirect is performed to the same route from which the request originated. Just be careful with the form names, you need them to match those in the Request, and also look at the validation rules in the same Request.

A
Anton Anton, 2021-12-03
@Fragster

Use dd instead of var_dump , or better yet, force yourself to set up xdebug once

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question