I have a table named Student with several fields :
'id', 'user_id', 'name', 'firstname', 'date_birth', 'sex', 'address', 'fk_city', 'phone', 'email', 'status', 'fk_license', 'date_registration'.
I have another table named Feedback with several fields also:
'id', 'user_id','instruction', 'description', 'fk_student'.
I also have 2 roles which are Admin and Member.
The administrator creates 2 recordings in the table Student, see below:
And the administrator creates 1 recording in the table Feedback for the Student Menier Jeremy.
When, I login with the address email test@gmail.com (Menier Jeremy) I see my 2 rubrics: (Student profil and feedback)
I can consult my information in my profil
Well!
Now, my problem is that when I click on my Feedback to consult the Feedback; it's empty ?
I don't understand why I retrieve the information for the rubric Student and no for the rubric Feedback?
Here is an idea of my code, is it a problem with my model?
public function index(Request $request)
{
$user = $request->user();
$feedbacks = Feedback::query()
->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
$query->whereHas('user', function ($query) use ($user) {
$query->where('email', $user->email);
});
})
->when($request->has('search'), function (Builder $query) use ($request) {
$query->join('students', 'feedbacks.fk_student', '=', 'students.id')->orderBy('students.name', 'asc')->where('students.name','like','%'.$request->input('search').'%');
})
->paginate(5);
return view('admin.feedbacks.index', compact('feedbacks'))
->with('display_search', $user->hasRole('admin'));
}
Thank you for your help.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2LgMxmr
via IFTTT
Aucun commentaire:
Enregistrer un commentaire