Column not found: 1054 Field Field 'email'

2019-08-28 01:08发布

问题:

I have 3 rubrics for now.

When, I login in the rubric Studentwith the email test.gmail.com I can see my informations private

Then, I LOGIN in the rubric Feedback always with the email test.gmail.com I have like error message:

SQLSTATE [42S22]: Column not found: 1054 Field Field 'email' unknown in where (SQL: select count (*) as aggregate fromreturnswhere email= test@gmail.com)

my fields on the table Feedbacks are:

protected $fillable = ['user_id','instruction', 'description', 'fk_eleve'];

My function index() is the following:

public function index(Request $request)

{   
    $user = $request->user();

    $feedbacks = Feedback::query()
    ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
        $query->where('email', $user->email);
    })
    ->when($request->has('search'), function (Builder $query) use ($request) {
     $query->join('eleves', 'feedbacks.fk_eleve', '=', 'eleves.id')->orderBy('eleves.nom', 'asc')->where('eleves.nom','like','%'.$request->input('search').'%');
     })
    ->paginate(5);

    return view('admin.feedbacks.index', compact('feedbacks'))
        ->with('display_search', $user->hasRole('admin'));
}

Thank you for your help.

回答1:

You most likely need to add the email column to your fillable array:

protected $fillable = ['user_id','instruction', 'description', 'fk_eleve', 'email'];

Did you further create a proper migration for this, like does the table have the column email?