I have 2 models: Profile and Student. The profile contains a primary key, id. Student model doesn't have any primary key, but one foreign key, profile_id, which links to profile.id. I have a function within my Student controller that activates the Student, setting the status from 0 to 1, when called. I am trying to use save() for the update of the value, but unable to do it, prompting me a message as such:
Column not found: 1054 Unknown column 'id' in 'where clause'
Can please advise? Thank you very much.
Student Model:
class Student extends Eloquent {
protected $primary_key = null;
public $incrementing = false;
protected $fillable = array('username', 'password', 'status', 'profile_id');
public function profile() {
return $this->belongsTo('Profile');
}
}
Profile Model:
class Profile extends Eloquent {
protected $fillable = array('firstname', 'lastname', 'email', 'phone');
public function student()
{
return $this->hasOne('Student', 'profile_id', 'id');
}
}
StudentController:
public function activate($id) {
$student = Student::where('profile_id', '=', $id)->first();
$student->status = 1;
$student->save();
return Redirect::to('students');
}