lundi 2 septembre 2019

Retrieve recording of a user after login

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:

enter image description here

And the administrator creates 1 recording in the table Feedback for the Student Menier Jeremy.

enter image description here

When, I login with the address email test@gmail.com (Menier Jeremy) I see my 2 rubrics: (Student profil and feedback)

enter image description here

I can consult my information in my profil

enter image description here

Well!

Now, my problem is that when I click on my Feedback to consult the Feedback; it's empty ?

enter image description here

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire