SQLSTATE[42S22]: Column not found: 1054 Unknown column

Posted 1 week ago by nipun

I am trying to make a relationship with lecturers table and users table. So this is the code of create_lecturers_table

public function up()
        Schema::create('lecturers', function (Blueprint $table) {




This is the Lecturer model

class Lecturer extends Model
    protected $table = 'lecturers';

    protected $fillable = [
        'class03', 'class03_stream' ,'class03_from','class03_to','remarks','created_user_id','updated_user_id',


    public function user(){
      return $this->hasMany('PMS\User');

This is the lecturer index function of the controller

public function index(Lecturer $model)
        return view('lecturers.index',['lecturers' => $model->paginate(15)]);

This is the create_users_table

 public function up()
        Schema::create('users', function (Blueprint $table) {


This is the User model

class User extends Authenticatable
    use Notifiable;


    public function lecturer(){
        return $this->belongsTo('PMS\Lecturer');

    protected $fillable = [
        'name', 'email', 'password','usertype',

With this what I wants to do is to view the User's name who will create the lecturer via System.So that I have echo the user's name as below in the view.blade.php

<td>{{ $lecturer->user->name }}

When I go to the view it generate this error.

ErrorException (E_ERROR)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.lecturer_id' in 'where clause' (SQL: select * from `users` where `users`.`lecturer_id` = 1 and `users`.`lecturer_id` is not null) (View: E:\BIT FINAL YEAR PROJECTS190419-using-template\resources\views\lecturers\index.blade.php)

Could someone please tell me what is the wrong . Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.