Authentication and Sweet Alert - Laravel

Asked

Viewed 280 times

0

Someone could help me, I have a tremendous doubt, I have researched so much and I have not found the solution. The scenario is as follows. I created a basic project with auth through php Artisan make:auth, installed and implemented Sweet Alert, but in this auth controller I can’t show Sweet Alert on the screen and already with another controller without auth I get good. From now on I appreciate the help.

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Animal;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use DB;
use Request;
use Alert;
use Session;
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:Usuario',
            'password' => 'required|string|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {

        $id = DB::table('usuario')->insertGetId(
            ['name' => $data['name'], 'email' => $data['email']
               ,'sobreNome' => $data['sobreNome'],  'password' => bcrypt($data['password']), ]
        );

        foreach (json_decode($data['listaPet']) as $area)
        {
            $idEspecie = DB::table('especie')->where('nome', 'LIKE', '%'.$area->Espécie.'%')->first();

            Animal::create([
                'usuario_id' => $id,
                'nome' => $area->NomedoAnimal,
                'especie_id' => $idEspecie->id,
                'raca' => $area->Raça,
                'dataNascimento' => $area->DatadeNascimento,
                'sexo' => $area->Sexo,
                'usesr_id' => 1,


            ]);

        }

        $usuario = new User();

        Alert::success('Usuário cadastro com sucesso!')->persistent("OK");
        return $usuario;

    }
    public function getEspecie(){
        $items = DB::table('especie')->get();

        return View('auth/register', compact('items',$items));


    }





}
  • Put the code in the question.

  • Code inserted.

  • You have already set up the $routeMiddleware in the archive app/Http/Kernel.php ?

  • Add that 'sweetalert' => \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class,

  • I just included, but Sweet Alert() was not shown and there were no errors.

  • also adds in $middlewareGroups, 'web' => [ \UxWeb\SweetAlert\ConvertMessagesIntoSweetAlert::class ]

  • Yes, include and unsuccessfully!

  • Find out what it was. I was returning the empty model when I gave it a new one. I am returning it filled the system logs in and the message is shown. Gratitude for your feedback.

  • Could you elaborate on the solution to the problem? I’m in the same situation here

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.