Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel验证封面图像必须是图像问题_Laravel_Laravel Blade - Fatal编程技术网

Laravel验证封面图像必须是图像问题

Laravel验证封面图像必须是图像问题,laravel,laravel-blade,Laravel,Laravel Blade,我的代码收到此错误消息。。我不明白为什么它会给我看这个 刀片模板文件: <div class="well" style="font-family:arial;"> <div class="well-body"> <form class="POST" action="/admin-panel/shows/store" enctype="multipart/form-data"> @csrf

我的代码收到此错误消息。。我不明白为什么它会给我看这个
刀片模板文件:

    <div class="well" style="font-family:arial;">
        <div class="well-body">
            <form class="POST" action="/admin-panel/shows/store" enctype="multipart/form-data">
            @csrf
            <table class="table table-striped">
                <tr>
                    <th>Show Name</th>
                    <th>
                    <div class="form-group">
                        <input type="text" class="form-control" name="name" placeholder="e.g, Avengers"/>
                    </div>
                    </th>
                </tr>
                <tr>
                    <th>Cover Image</th>
                    <th>
                        <div class="form-group">
                            @csrf
                            <input id="cover_image" type="file" name="cover_image">
                        </div>
                    </th>
                </tr>
            </table>
            <button type="submit" class="btn btn-primary pull-center">Submit</button>
            </form>
        </div>
    </div>
我还想补充一个事实,一个类似的东西在后期创作中效果很好。我可以用它们来区分这两个代码。它们看起来一模一样。是否可以写入操作=“/admin panel/shows/store”这将是一个问题

dd($request->input('cover_image')ss:

dd($request->file('cover_image'))ss:


更新:我没有正确布线。

我会颠倒
封面图片
的规则顺序,并删除空格:
'cover\u image'=>'required | image | max:1999'
。另外,确保你确实上传了一张图片(
png
jpg
,等等)。另外,
操作=“/admin panel/shows/store”如果您的路由与
管理面板/shows/store
匹配,则不存在问题。
首选方法是
action=“{{url(''.')}”
action=“{{route('.')}”
,但省略助手仍然可以工作。更改了它…但仍然不工作…我正在上载一个.jpg文件…嗯…其他一切看起来都很好。
enctype=“multipart/form data”
type=“file”
name=“cover\u image”
都是正确的,验证规则应该是正确的。你能上传一张图片并在
$this->validate()
之前做一个
dd($request->文件(“cover\u image”)
吗?旁注:你有两张
@csrf
,只需要一张。这可能不是问题,但需要修复。再次检查我的评论,它不是
$request->input()
,使用
$request->file()
访问文件。我当前无法复制您的问题。
$request->input(“cover\u image”)
对我来说总是
null
(应该是这样),但是
$request->file(“cover\u image”)
在我上传文件时显示
上传文件{…}
。您是否发布了完整的表单?是否有另一个
具有相同的
name=“cover\u image”
?是否是ajax请求?等等。
public function store(Request $request)
{
    $this->validate($request,[
        'name' => 'required | max:140',
        'plot' => 'required',
        'cover_image' => 'image | required | max:1999'

    ]);
    -----Rest of the code ---
}