您好我正在尝试上传照片,但我没有在我的数据库中获取照片的文件名..照片成功上传到我的文件夹。我在我的控制器中有这个
public function postCreatePost(Request $request)
{
if ($request->hasFile('avatar'))
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save( public_path('uploads/posts/' .$filename));
Auth::user()->posts()->create([
'body' => $request->body,
'username' => Auth::user()->name,
'photo' => $filename,
]);
$posts = Post::orderBy('created_at', 'desc')->get();
return view('home', ['post' => $posts]);
}
任何人都可以告诉我我错过了什么