samedi 24 août 2019

no display when I login

For to be simple, I have 2 tables Students and Feedbacks.I also have 2 roles which are Admin and Member .

There is only the administrator which can create several recordings. The member can just to connect and see his profil and his feedback.

Here is, the differents fields:

Class Student = 'user_id', 'name', 'firstname', 'date_birth', 'sex', 'address', 'fk_city', 'phone', 'email', 'status', 'fk_license', 'date_registration'

Class Feedback = 'user_id','instruction', 'description', 'fk_student'

Well !

The administrator creates 2 students, see below:

enter image description here

And a feedback here:

enter image description here

When, I login with the address email test@gmail.com 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

However, no display on my rubric Feedback. I don't know why ???

enter image description here

I think my problem must be in my function index() of my Controller Feedback.

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