samedi 17 août 2019

ID and connection

In my administrator panel, I have 2 Roles, admin and former:

enter image description here

For now, I have 3 users:

  • the first role is admin, the pseudo is admin and email address is admin@gmail.com

  • the second role is former, it has like pseudo Remace and email address is test@gmail.com

  • the third user is always a former, it has like pseudo Gofette and email address is ledeluge1990@gmail.com

enter image description here

For information, the administrator is the only one to create records.

Here, I have 2 recordings: (It's the informations of the formers)

enter image description here

Now, my goal is that each former has access to his informations.

So, the first former is Remace with email adresse test@gmail.com.

I log in with email adresse of Remace ( test@gmail.com )

I see this :

enter image description here

In fact, I retrieve the informations of Gofette and not those of Remace, why ???

Now, I want to connect with the user Gofette with email adresse ledeluge1990@gmail.com...

I see nothing ???

enter image description here

I think my problem is in my function index() ????

public function index()
    {   

        if($has_role = auth()->user()->hasRole('admin')){
            $garages = Garage::oldest()->paginate(5);
            return view('admin.garages.index', compact('garages'));
        } else{
            $garages = Garage::where('id', Auth::user()->id)->paginate(5);
            return view('admin.garages.index', compact('garages'));
        }

    }


   public function create()
    {

        $localites = Localite::all();
        return view('admin.garages.create', compact('localites', 'garages'));
    }

    public function store(Request $request)
    {      


        $request->validate([
           'nom' => 'required|string|max:25|min:3|alpha',
            'adresse' => 'required|string|max:50|min:12',
            'fk_localite' => 'required',
            'telephone' => 'required|string|min:8|max:11',
            'email' => 'required|email|max:25|min:10'


         ]);

        $exists = Garage::where('nom', $request->get('nom'))->where('adresse', $request->get('adresse'))->where('fk_localite', $request->get('fk_localite'))->where('telephone', $request->get('telephone'))->where('email', $request->get('email'))->count();

       if (!$exists){
            Garage::create($request->all());
            return redirect()->route('garages.index')
                ->with('success', 'Un nouvel enregistrement a été effectué');
        }

        else{
            return redirect()->route('garages.index')
                ->with('error', 'Doublon, cet enregistrement existe déjà! ');

        } 

    }

Thanks a lot for your help.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NfsVQT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire