我在将'cover_image'迁移到phpmyAdmin时遇到问题。每当我尝试上传照片时,都会出现错误:
SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'cover_images'
以下是我的代码:
if($request->hasFile('cover_image')) {
//get``
$fileNameWithExt = $request->file('cover_image')->getClientOriginalName();
//get filename
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
//get ext
$extension = $request->file('cover_image')->getClientOriginalExtension();
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//upload image
$path = $request->file('cover_image')->storeAs('public/cover_images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
//Create Post
$post = new Post;
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->user_id = auth()->user()->id;
$post->cover_images = $fileNameToStore;
$post->save();
return redirect('/posts')->with('success', 'Post Created');
答案 0 :(得分:0)
要在表格中添加新列,请检查documentation:
<!-- language: lang-php -->
php artisan create:migration add_cover_images_to_posts_table --table=posts
Schema::table('posts', function (Blueprint $table){
$table->string('cover_images');
});
cover_images
。