简体   繁体   English

不能在表单中使用动作属性

[英]Cant use action attribute in form

So I am making a crud application.所以我正在制作一个 crud 应用程序。 But i have a problem in my edit part.但是我的编辑部分有问题。 I setted up the edit view and the action to the update function, where I setted up the update too.我设置了更新 function 的编辑视图和操作,我也在其中设置了更新。 But when I hit submit it wont redirect me to the page and it wont update, it will stay to the edit page, and its not giving me any error!但是当我点击提交时,它不会将我重定向到该页面并且它不会更新,它会停留在编辑页面,并且不会给我任何错误!

This is my form(don't mind the style):这是我的表格(不要介意风格):

<form method="post" action="{{route('profile.update', $user->id)}}" enctype="multipart/form-data">
            @csrf
            @method('PATCH')
            <div class="col-8 offset-2">
                <div class="row">
                    <h1>Edit Profile</h1>
                </div>
                <div class="form-group row">
                    <label for="title" class="col-md-4 col-form-label">Title</label>

                    <input id="title"
                           type="text"
                           class="form-control @error('name') is-invalid @enderror"
                           name="title"
                           value="{{$user->profile->title}}"
                           required autocomplete="title" autofocus>

                    @error('title')
                    <span class="invalid-feedback" role="alert">
                         <strong>{{ $message }}</strong>
                     </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="caption" class="col-md-4 col-form-label">Description</label>

                    <input id="description"
                           type="text"
                           class="form-control @error('name') is-invalid @enderror"
                           name="description"
                           value="{{$user->profile->description}}"
                           required autocomplete="description" autofocus>

                    @error('description')
                    <span class="invalid-feedback" role="alert">
                         <strong>{{ $message }}</strong>
                     </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="url" class="col-md-4 col-form-label">Url</label>

                    <input id="url"
                           type="text"
                           class="form-control @error('name') is-invalid @enderror"
                           name="url"
                           value="{{$user->profile->url}}"
                           required autocomplete="url" autofocus>

                    @error('url')
                    <span class="invalid-feedback" role="alert">
                         <strong>{{ $message }}</strong>
                     </span>
                    @enderror
                </div>
                <div class="row">
                    <label for="image" class="col-md-4 col-form-label">Profile Image</label>
                    <input type="file" class="form-control-file" id="image" name="image">

                    @error('image')
                    <strong>{{ $message }}</strong>
                    @enderror
                </div>

                <div class="row pt-4">
                    <button type="submit" class="btn btn-primary w-25">Save Profile</button>
                </div>
            </div>
        </form>

Here is my route:这是我的路线:

Route::patch('/profile/{user}', [ProfilesController::class, 'update'])->name('profile.update');

Here is my controller:这是我的 controller:

public function update(User $user)
    {
        $data = request()->validate([
            'title'=>'required',
            'description'=>'required',
            'url'=>'url',
            'image'=>'file|mimes:jpeg,jpg,png,giv,svg'
        ]);

        auth()->user()->profile()->update($data);

        return redirect()->route('profile.show', $user->id);
    }

So I ran the code to display the validation errors:所以我运行代码来显示验证错误: 在此处输入图像描述

And I got this:我得到了这个: 在此处输入图像描述

So I didn't have a valid URL and than I fixed it to this, now I can update:所以我没有有效的 URL 而不是我将其修复为这个,现在我可以更新: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM