I'm trying to see why i'm getting MethodNotAllowedHttpException error with put when its working fine with post method
Route::resource('record/{id}/details', 'RecordDetailController');
this works:
{{ Form::open(array('url' => '/records/' . $record->id . '/details/', 'method' => 'post')) }}
while this:
{{ Form::open(array('url' => '/records/' . $record->id . '/details/', 'method' => 'put')) }}
is getting MethodNotAllowedHttpException
thanks for the help, i found the answer from this Laravel 5 MethodNotAllowedHttpException PUT
just put
{{ method_field('PUT') }}
Related
With LaravelCollective, we can populate a form like this :
{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}
If we declare an input like this (inside a view) :
{{ Form::text('name') }}
the field will be automatically filled by the attribute "$user->name".
However, if we want to add some custom parameters (like class) :
{{ Form::text('name', ['class' => 'form-control']) }}
we have the following error :
htmlspecialchars() expects parameter 1 to be string, array given,
OK so framework is waiting for the second parameter...
{{ Form::text('name', '', ['class' => 'form-control']) }}
But in that case, we lose the "auto-populate" feature.
Is there a solution to custom form fields, and keeping the auto populate functionality ?
Thanks !
Solution given by porloscerros :
{{ Form::text('name', NULL, ['class' => 'form-control']) }}
I'm an amateur in laravel. I use laravel 5.4. so I want to make process delete without form binding but I have an error message like this. Please tell me how to solving this.
route:
Route::delete('test/{id}','TestController#destroy');
My Form:
<td><button type="button" class="btn"><a href="{{ action('TestController#destroy', $post['id']) }}" method="post" >Hapus</button>{{ csrf_field() }}{{ method_field('DELETE') }}
</td>
My Controller:
public function destroy($id)
{
$post = Post::find($id);
$post->delete();
return redirect()->to('coba/test');`
}
Href on an anchor html element will result in a GET call but your route expect a Delete call. You have some ways to make sure you will result in a delete call.
One of the most common ways is to use a form instead to post data to your server.
Delete
{{ Form::open(['url' => 'test/'.$post->id, 'method' => 'DELETE']) }}
{{ Form::button('delete', ['type' => 'submit',
'class' => 'btn']) }}
{{ Form::close() }}
Edit
{{ Form::open(['url' => 'coba/test/'.$post->id.'/edit', 'method' => 'POST']) }}
{{ Form::button('delete', ['type' => 'submit',
'class' => 'btn']) }}
{{ Form::close() }}
For best practise I recommend to use {{ Form::open(...) }} {{ Form::close() }} only once and refactor your controller code so it can read the value from the buttons and translate that in the corresponding id of the post so you dont have multiple html forms in your code.
I have from:
{{ Form::open(array('url' => 'announcements', 'class' => 'form-inline', 'method' => 'GET')) }}
And checkbox in form:
{{Form::checkbox('only_subscriptions', '1', old('only_subscriptions'))}}
After submit I get empty old():
old('only_subscriptions')
You would use ->withInput() in redirect(), not in view().
I know that to insert a attribute in forms in laravel we do something like below
{{ Form::open(array('url' => 'comment', 'method' => 'post')) }}
But what i want to do is insert a attribute like this and not in commas
<form data-abide>
Because I'm using foundation as a front end framework so need to use its validation.
You can add it similar way you add method :
{{ Form::open(array('url' => 'comment', 'method' => 'post', 'data-abide' => 'formclass', 'onSubmit' => 'return false;')) }}
Is there anyway i can get link_to_action in the form of method 'post'?
Here's my code
{{ link_to_action('SummaryController#viewSummaryStudent', 'View Summary', array($students->student_id),
array('class' => 'btn btn-info')) }}
Please help. Thank you!