php - Eloquent looks for wrong column -


my migration

schema::create('tickets', function(blueprint $table)     {         $table->increments('id');         $table->text('subject');         $table->text('body');         $table->integer('author_id')->unsigned();         $table->timestamps();      });      schema::table('tickets', function($table)     {         $table->foreign('author_id')->references('id')->on('users');     }); 

relations

public function createdtickets() {     return $this->hasmany('app\ticket'); }    public function author(){     return $this->belongsto('app\user', 'author_id'); } 

and store method

    public function store(ticketrequest $request) {     $ticket = new ticket($request->all());     auth::user()->createdtickets()->save($ticket);      return redirect('tickets'); } 

when try save new ticket recive error

queryexception in connection.php line 624: sqlstate[hy000]: general error: 1 table tickets has no column named user_id (sql: insert "tickets" ("subject", "body", "user_id", "updated_at", "created_at")

where else need specify fk except relations?

you need specify desired column name in both of relation methods.

public function createdtickets() {     return $this->hasmany('app\ticket', 'author_id'); } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -