php - Action url for a form
Get the solution ↓↓↓My routes:
Route::group(['prefix' => 'product'], function () {
Route::get('{id}', 'ProductController@product')->where('id', '[0-9]+');
Route::post('{id}/add', 'ProductController@addToCart')->where('id', '[0-9]+');
});
From theproduct/{id}
page i wan't to do a POST toproduct/{id]/add
But what is the best way to get the form action url?
Now i have:
<form method="POST" action="{{ Request::url() }}/add">
It works, but I don't like it... And there must be a beter way...
<form method="POST" action="{{ action('ProductController@addToCart') }}/add">
Given me an exception...
Missing required parameters for [Route: ] [URI: product/{id}/add]. (View: .../resources/views/product/product.blade.php)
Answer
Solution:
If you dislike that, you can use route naming:
Route::post('{id}/add', 'ProductController@addToCart')
->name('product.add')
->where('id', '[0-9]+');
and then:
<form method="POST" action="{{ route('product.add', $id) }}">
where$id
is a id of a element to pass.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: err_ossl_pem_no_start_line
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.