I'm trying to publish post with user that register in my app, but this error happened:
And I'm using XAMPP and my posts table is this picture
And this error is in phpMyAdmin:
My PostController
is:
use App\Post;
class PostsController extends Controller
{
public function __construct()
{
$this->middleware('auth')->except(['index','show']);
}
public function index()
{
$posts=Post::latest()->get();
return view('posts.index',compact('posts'));
}
public function show(Post $post)
{
return view('posts.show',compact('post'));
}
public function create()
{
return view('posts.create');
}
public function store()
{
$this->validate(request(),[
'title'=>'required',
'body' => 'required|min:5'
]);
Post::create(request([
'title' => request('title'),
'body' => request('body'),
'user_id' =>auth()->id()
//auth()->user()->id*/
]));
return redirect()->home;
}
}
and Post Model:
class Post extends Model
{
public function comments()
{
return $this->hasMany(Comment::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}