vendredi 9 août 2019

Column not found: 1054 Champ 'feedbacks.student_id

I have a belongsTo relationship between Feedback and Student.

In my table Students I have 3 fields (id, name, firstname).

In my Feedbacks I have 3 fields (id, instruction, fk_student).

My sort with alphabetical order is incorrect. I have as message:

Column not found: 1054 Champ 'feedbacks.student_id

public function index(Request $req) 
    {

    if ($req->search == "") {
        $feedbacks = Feedback::join('students', 'feedbacks.student_id', '=', 'students.id')->orderBy('students.name', 'asc')->select('feedbacks.*')->paginate(5);
        return view('admin.feedbacks.index', compact('feedbacks'));

    } else {

        $validated = $req->validate([
            'search' => 'alpha', 
        ]);

        $feedbacks = Feedback::join('students', 'feedbacks.student_id', '=', 'students.id')->where('students.name','like', '%' . $req->search . '%')->orderBy('students.name', 'asc')->select('feedbacks.*')->paginate(5);

        return view('admin.feedbacks.index', compact('feedbacks'));
        }

    }

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire