我正在学习Laravel,并从Laracasts开始从零开始学习Laravel 5.7(我正在使用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
因此,尽管定义了路线,但好像没有击中路线。我不知道自己在做错什么,因为我确实做了视频中正在做的事情,所以我陷入了困境。 有人可以告诉我这是怎么回事吗?
答案 0 :(得分:0)
将补丁更改为发布
Route::patch('/tasks/{task}', 'ProjectTasksController@update');
至
Route::post('/tasks/{task}', 'ProjectTasksController@update');
然后添加参数
public function update(){
dd("hello");
}
至
public function update($task){
dd("hello");
}
答案 1 :(得分:0)
似乎是路由缓存的问题,您是否尝试过使用工匠清除缓存?
php artisan route:clear
php artisan config:clear
php artisan view:clear
php artisan cache:clear
这是4条命令,用于清除Laravel为您的configs
,routes
和views
可能拥有的所有缓存。
答案 2 :(得分:0)
检查您是否在表单内有表单,或者表单组件是否被其他表单标签包裹;我有同样的问题。 您可能会在父刀片中发现您有一个表单,而单独的子 (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>