[英]Why will this form not submit in Laravel?
我只是在學習 Laravel 並從頭開始學習 Laravel 5.7(我使用的是 Laracasts 的 5.8)課程。 我們創建一個新的控制器來處理與項目相關的任務。 我們在特定項目的詳細信息頁面上顯示任務。 到目前為止,所有這些都有效。 然后,我們添加一個復選框,指示任務何時完成。 復選框位於更改時提交的表單中。 這是我的表單代碼。
@section('content')
<div class ="col col-md-6">
<form action="/tasks/{{$task->id}}" method="POST">
@method("PATCH")
@csrf
<label class = "checkbox" for="completed">Completed</label>
<input type="checkbox" name="completed" onChange="this.form.submit()">
</form>
</div>
@endsection
目前,在我的控制器中,我有這個功能,但我只是想看看它是否正在運行該功能,所以我死了並轉儲了。 或者這就是它應該做的事情..
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProjectTasksController extends Controller
{
public function update(){
dd("hello");
}
}
而且,在我的 web.php 文件中,這就是我設置路由的方式。
Route::patch('/tasks/{task}', 'ProjectTasksController@update');
然而,它不起作用。 當我選中其中一個復選框時,URL 更改為此
http://127.0.0.1:8000/projects/1?_method=PATCH&_token=0menrjzIOdiSn0SEu51unY114oKU8kZ2i2B5zy4p&completed=on
因此,盡管定義了路線,但它就像沒有擊中路線一樣。 我不知道我做錯了什么,因為我已經完成了視頻中正在做的事情,所以我被卡住了。 有人能告訴我這有什么問題嗎?
將補丁更改為發布
Route::patch('/tasks/{task}', 'ProjectTasksController@update');
到
Route::post('/tasks/{task}', 'ProjectTasksController@update');
然后添加參數
public function update(){
dd("hello");
}
到
public function update($task){
dd("hello");
}
似乎是路由緩存的問題,您是否嘗試過使用 artisan 清除緩存?
php artisan route:clear
php artisan config:clear
php artisan view:clear
php artisan cache:clear
這些是清除 Laravel 可能為您的configs
、 routes
和views
擁有的所有緩存的 4 個命令。
檢查您的表單中是否有表單,或者表單組件是否包含在其他表單標簽中; 我有同樣的問題。 您可能會在父刀片中發現您有一個表單,而單獨的子 (medical-info-components.payment) 刀片也有一個表單。
<div>
<fieldset>
@if ($stripe)
<div class="card-body">
<script src="https://js.stripe.com/v3/"></script>
<hr>
<div class="col-md-12">
<div class="card">
<div class="card-body">
<strong class="text-bold" style="font-size:20px;">Make Payment of
{{$currency}} {{$price}}
</strong>
<br>
<strong style="font-size:20px;">Please make payments by entering
your Credit or Debit
Card</strong>
</div>
</div>
</div>
<div class="col-md-6" style="float:right;">
<form action=" {!! action('\App\Http\Controllers\PaymentController@store') !!}" method="POST"
id="payment-form" ata-cc-on-file="false"
data-stripe-publishable-key="{{env('pk_test_')}}"
enctype="multipart/form-data">
@csrf
{{-- <input type="hidden" class="" name="stripeToken" id="stripeToken" wire:model.lazy="stripeToken" /> --}}
<div class="form-row">
<label for="card-element">
Your Name
</label>
<input type="text" name="name" class="form-control" wire:model.lazy='name'
placeholder="Enter Your Name" id="">
<label for="card-element">
Your Payable Amount
</label>
<input type="text" name="grandTotal" class="form-control" wire:model.lazy='amount'
placeholder="Enter Your Amount" id="">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element" class="form-control">
<!-- A Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors. -->
<div id="card-errors" role="alert"></div>
</div>
<input type="button" class="previous action-button-previous btn btn-dark"
style="margin-left: -11rem; margin-top:15px;" value="Previous" wire:click='previousStep' />
<input type="submit" class="next action-button btn btn-primary"
style="float:right; margin-top:15px;" value="Confirm" />
</form>
</div>
</div>
@elseif($paypal) @elseif($mpesa) @endif
<div class="row">
<div class="col-md-12">
</div>
</div>
</fieldset>
然后在母組件里面,你可能有這個
<div>
<!-- call -->
<section class="slice">
<div class="container" id="grad1">
<div class="row justify-content-center mt-0">
<div class="col-12 text-center p-0 mt-3 mb-2">
<div class="card px-0 pt-4 pb-0 mt-3 mb-3 border-0 rounded-lg">
<div class="card-body px-5">
<div class="row">
<div class="col-md-12 mx-0">
{{-- <form id="msform"> --}}
<!-- progressbar -->
@livewire('medical-info-components.payment')
{{-- </form> --}} <!--You see here we have form wrapping our component that has form, you need to take it down-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.