I'm trying to do follow system without any laravel libray. I got this error when I submit form. How can I fix it? I think error is about my user model and my follow model relationship but I couldn't solve.
My error is:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'muzik.follows' doesn't exist (SQL: insert into
follows
(following_id
,follower_id
,updated_at
,created_at
) values (12, 30, 2021-04-02 22:32:50, 2021-04-02 22:32:50))
My User model contains the following relationship:
public function follows(){
return $this->hasMany('App\Models\Follow');
}
My User model contains the following relationship:
public function user(){
return $this->belongsTo('App\Models\User');
}
My controller is:
public function follow(Request $request){
$request->validate([
'follower_id'=>['required'],
'following_id'=>['required'],
]);
$follower_id = $request->follower_id;
$following_id = $request->following_id;
$save = Follow::create([
'following_id' => Auth::user()->id,
'follower_id' => $follower_id,
]);
if($save){
return back();
}else{
return back();
}
}