dimanche 3 janvier 2021

I want to redirect afrter complete both insert from laravel request

so I have this store function at my Controller

public function store(Request $request)
{
    Penghuni::create([
        'nama_penghuni' => $request->nama_penghuni,
        'email' => $request->email,
        'phone' => $request->phone,
        'tower' => $request->tower,
        'no_unit' => $request->no_unit
    ]);

    User::create([
        'name' => $request->nama_penghuni,
        'email' => $request->email,
        'password' => Hash::make($request['password']),
        'role' => 'penghuni',
    ]);

    return redirect(route('penghuni.index'));
}

what I want is make sure both insert is success, because the current result I got is when Penghuni create is done but the user is fails it keeps getting redirected

hope someone can help, I use laravel 5.8

thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire