I have 2 users roles in my application, admin and former.
The admin can create several formers...
If, I connect me with the ID 1 ? I retrieve the information of the former.
So, my function index() allows to retrieve id of the user
public function index()
{
if($has_role = auth()->user()->hasRole('admin')){
$formers = Former::first()->paginate(5);
return view('admin.formers.index', compact('formers'));
} else{
$formers = Former::where('email', Auth::user()->email)->paginate(5);
return view('admin.formers.index', compact('formers'));
}
}
Well !
For the user admin, I would like to create a search bar...
I had created before a function index() and which worked
public function index(Request $req)
{
if ($req->search == "") {
$formers = Former::paginate(5);
return view('admin.formers.index', compact('formers'));
} else {
$validated = $req->validate([
'search' => 'alpha',
]);
$formers = Former::where('nom', 'LIKE', '%' . $validated['search'] . '%')->paginate(5);
$formers->appends($req->only('search'));
return view('admin.formers.index', compact('formers'));
}
}
Now, I would like to adapte my 2 actions in a function, is it possible according you?
Do you think that I can get the user_id and make a search bar in the same function?
Thank you
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31O2sxI
via IFTTT
Aucun commentaire:
Enregistrer un commentaire