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>
Related
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'>
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 use Laravel HTML to create form but I have problem, so in creating form I have:
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}
#include('vouchers.form',['submitButtonText'=>'Click to Add New Vocuher'])
{!! Form::close() !!}
But when I see my HTML form in browser there is just:
<form method="POST" action="http://localhost:8888/vouchers" accept-charset="UTF-8">
<input name="_token" type="hidden" value="dfgdfgdfgdfgdf">
so where is
enctype="multipart/form-data"
which allow me to upload files from form ?
Why I don't get this HTML output:
<form method="POST" action="https://bedbids.com/chats" accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="dsfdfgdfgdfgdfg">
What is the problem here exactly ?
Your syntax is wrong. The following works for me:
{{Form::open(array('url' => 'your_url', 'method' => 'post', 'files' => true))}}
Change url with route as below.
{{!! Form::open(['route'=>'vocuhers','class'=>'your_class','files'=>true]) !!}}
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}
change It to
{!! Form::open(['url'=>'vocuhers','files' =>true,'enctype'=>'multipart/form-data']) !!}
as Markinson said
Change it to like this:
{!! Form::attributes(['enctype'=>"multipart/form-data"])open(['url'=>'vocuhers']) !!}
I recently upgraded from laravel 5.1 to 5.2 and now I'm getting an error of Missing required parameters for [Route: example.destroy] [URI: example/{args}].
The error occurs here:
<form class="form-horizontal" action="<?php echo route('example.destroy'); ?>" method="post"> on the action attribute of the form.
Here's how the route was registered on the route.php
Route::resource('example', 'ExampleController');
When I was in 5.1, there was no error with this line. Just went I upgrade to 5.2, it now occurs.
The functionality of this is that it will allow user to delete multiple entries by checking the checkboxes that they wish to be deleted. Then upon submit, it will redirect to the destroy method on the controller.
You can try the following
<form class="form-horizontal" action="<?php echo
url('example'); ?>" method="post">
Route::post('example', 'ExampleController#destroy');
I had the same problem when updating my app to Laravel 5.2.
Apparently, Laravel 5.2 require a valid Route to "destroy resource", ex:
/my-route/item-to-destroy/{id}
Here, in our apps I'm putting an "{id} = 0" or "{id} = null", at the end of each route (when calling a "route destroy" that is not yet ready).
In your case, it would be similar to that:
<form action="<?php echo route('example_route.destroy', ['id'=>0]); ?>" method="post">
or, declare a valid resource id:
<form action="<?php echo route('example_route.destroy', ['id'=>$object->id]); ?>" method="post">
Try with this:
<form class="form-horizontal" action="<?php echo route('example.destroy', $record->id); ?>" method="post">
or Laravel way:
{!! Form::open(['route' => ['example.destroy', $record->id],
'method' => 'delete']) !!}
{!! Form::close() !!}
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">