vendredi 27 septembre 2019

Connection for a user

I have for my table 'Student' 5 fields id, name, firstname, email, phone.

My question: I would like the user to connect by putting his name what should I change?

public function index(Request $request)
    {   
        $user = $request->user();
        $students= Student::query()
        ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
            $query->where('email', $user->email);
        })
        ->when($request->has('search'), function (Builder $query) use ($request) {
            $query->where('name', 'like', '%'.$request->input('search').'%');
        })
        ->paginate(5);



    return view('admin.students.index', compact('students'))
        ->with('display_search', $user->hasRole('admin'));
    }

Here:

$query->where('email', $user->email);

I have to put this?

  $query->where('name', $user->name);

Thank you for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire