I made a blade component to make it easier to create input forms. but I'm stuck on if have two parameters on my route.
I put create and update in single page, so this is may code:
#if(isset($rack))
<form action='{{ route("warehouse.update", ["warehouse" => $warehouse->id]) }}' method='POST'>
#method('PUT')
#else
<form action='{{ route("warehouse.store", ["warehouse" => $warehouse->id]) }}' method='POST'>
#method('POST')
#endif
/** FORM INPUTS BELOW HERE*/
</form>
and this is how I refactor mycode:
<x-form title='Warehouse' route-prefix='warehouse' key='warehouse' :model='$warehouse??null'>
/** FORM INPUTS BELOW HERE*/
</x-form>
the problem is how to put second parameter like
<form action='{{ route("warehouse.update", ["warehouse" => $warehouse->id, "rack" => $rack->id]) }}' method='POST'>
Related
The storeClientRequest Cannot be triggered, is there any mistake here ? When I hit submit, the page shows 404 Not found
Form
<form class="needs-validation" novalidate method="POST" action="store-client-request/{{ Auth::user()->id }}">
#csrf
//////content
</form>
Route
Route::group(['prefix'=>'user', 'middleware'=>['isUser','auth']], function(){
Route::post('store-client-request/{user}', [UserController::class, 'storeClientRequest']);
});
Controller
function storeClientRequest(User $user)
{
dd('hi');
return redirect()->back()->with("message", "Create request successfully");
}
Add a name to your route :
Route::post('store-client-request/{user}', [UserController::class, 'storeClientRequest'])->name("store.client.request");
Make sure you run
php artisan optimize
Reference your route by name in the opening form tag :
action="{{ route('store.client.request', ['user' => Auth::user()->id]) }}">
That way, it doesn't matter (a) what the route prefix is (that it looks like you've forgotten to include) or (b) if the address to the route changes later down the line - the {{ route() }} blade directive will always pull in the correct URL, along with the relevant parameters.
As I see through you code: your full route is /user/store-client-request/{user}
Therefore in you action you should put
<form class="needs-validation" novalidate method="POST" action="/user/store-client-request/{{ Auth::user()->id }}">
#csrf
//////content
In your Route there is /user/store-client-request/{user}
So Add this in your Action
<form class="needs-validation" novalidate method="POST" action="/user/store-client-request/{{ Auth::user()->id }}">
</form>
I have a form like this:
<form class="form-horizontal" role="form" method="POST" name="myform" id="myform" action="{{ url('/mypage/') }}">
{{ csrf_field() }}
<div id="somecontent">
</div>
<div id="abutton">
</div>
</form>
Then some Jquery like this:
$('#somecontent').html('<select class="form-control" id="myselect" form="my"><option value="1">Hello</option><option value="2">World</option></select>');
And then I add a button like this:
button = $('<button type="submit" form="myform" class="btn btn-theme">Send</button>');
$('#abutton').html(button);
And I also change the action dynamically:
$("#myform").attr("action","/mypage/" + item_id);
Then I got this in the web file:
Route::post('/mypage/{item_id}','mycontroller#do_something');
And then do this in the controller:
public function do_something($item_id,Request $request){
dd($request);
}
But the $request is empty, it does not contain the value selected in the dynamically generated select.
Any ideas why?
you haven't added name attribute of select, add name attribute and see it will populate into $request.
Try below code.
$('#somecontent').html('<select name="select_name" class="form-control" id="myselect" form="my"><option value="1">Hello</option><option value="2">World</option></select>');
Missing argument 2 for App\Http\Controllers\Company\OrderController::store()
I got this error in my store controller, my form is passing 2 parameters but the second one is not found.
Route: Route::resource('order', 'OrderController');
$company gets converted to a model in the controller.
The form:
<form class="form-horizontal" role="form" method="POST" action="{{action('Company\OrderController#store', [$company,$orderid])}}">
{{ csrf_field() }}
<button type="submit" class="btn btn-primary">Accept</button>
</form>
Any ideas?
Thanks!
If you created store route with Route::resource() it doesn't expect any parameters and should look like this:
public function store(Request $request)
So, you need to pass data using hidden inputs, like:
{!! Form::hidden('data', 'some data') !!}
And then get data in controller with:
$data = $request->data;
You should specify the key-value pair like this:
['company_id' => $company->id, 'order_id' => $order->id]
So your form would look like:
<form action="{{ action('Company\OrderController#store', ['company_id' => $company->id, 'order_id' => $order->id]) }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-primary">Accept</button>
</form>
Hope this helps!
im trying to buld a complate form using laravel but i cant make this right :
<form class="form-horizontal">
<fieldset>
{{Form::open(array('url'=>'register'))}}
but clearly this does not do anything with my data base so i want this :
<form class="form-horizontal" action={{ url('our/target/route') }}" method="post">
but when i do this my form is not horizontal anymore and becomes something un watchable
so what is the problem ?
Now you have two <form>
Try this:
{{ Form::open(array('url' => 'register', 'class' => 'form-horizontal')) }}
<fieldset>
I am trying to set a Password reminder in restful way. (Following this tutorial http://laravel.com/docs/4.2/security#password-reminders-and-reset but trying to do it in restful way)
The route looks like this,
Route::group(array('prefix' => 'api/v1'), function(){
Route::resource(
'password', 'RemindersController',
array(
'only' => array('store', 'show', 'update')
)
);
});
RemindersController starts as,
public function update()
{
}
The password reset url is
http://192.x.x.x:8000/api/v1/password/3adb8b0454144ef5aeaa333faa5c575bd833e03d
From this url loading reset.blade as follows,
<form action="{{ action('RemindersController#update') }}" method="PUT"
...
<input type="submit" value="Reset Password"> </form>
But when loading this page, the form action seems to have some issues, the action url does not seem to be right.
<form action="http://192.x.x.x:8000/api/v1/password/%7Bpassword%7D" method="PUT">
What is the right way to provide action property in the form for this? How can I pass the password reset details to 'update' method in Reminder controller?
In the mentioned tutuorial it is like
action="{{ action('RemindersController#postReset') }}" method="POST"
What will change when using the restful resource way?
Got it right by following the suggestion from this site with the following modification,
<form action="{{ URL::to('api/v1/password/update') }}" method="POST">
<input name="_method" type="hidden" value="PUT">