Laravel resource controller destroy - laravel

I'm having trouble using the destroy method from my resource controller. I know in html you can only POST/GET so I used a hidden value but it comes up with a MethodNotAllowedHttpException error. Here is my code:
Modal where the Delete Button is:
<div class="modal-footer">
<form action="/wod/{{$wod->id}}" method="POST">
{{ csrf_field() }}
{{ method_field('DELTE') }}
<button type="button" class="btn btn-default navbar-inverse" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-default navbar-inverse"><a class="bottom" href="/wod/{{$wod->id}}/edit">Edit</a></button>
<button class="btn btn-primary navbar-inverse" value="submit" type="submit">Delete</button>
</form>
</div>
And here is my resource controller:
public function destroy(Id $id)
{
//
Wod::find($id)->delete();
return redirect()->action("WodController#index");
}

you have a typo in {{ method_field('DELTE') }}
it should be {{ method_field('DELETE') }}

Related

django-summernote - clear/reset form fields

I am trying to clear/reset form fields which one of them is SummernoteWidget
<form>
{% csrf_token %}
{{ form.as_p }}
<button type="reset" class="btn btn-warning pull-right" id="reset_btn">Reset Fields</button>
<button type="submit" class="btn btn-success pull-right" id="submit-btn">Submit</button>
</form>
<script src='{% static "summernote/summernote.js" %}'></script>
all fields are getting cleared besides the SummernoteWidget.
I have tried with a JavaScript as follows:
<script>
$('#reset_btn').click(function(){
$("#summernote").summernote('reset');
});
</script>
with out good results.
how can I achieve this ?

Laravel | Form not submitting to route given in action [SOLVED]

I'm trying to submit a form to the right route using the action:
<form action="{{ route('document.destroy', $d->id) }}" method="POST" style="display: inline;">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<span type="text" value="" class="btn btn-success" readonly="readonly">
{{ $d->file_name }} ({{ $d->file_size }}) <i class="fa fa-times"></i>
</span>
<button class="btn btn-xs btn-default" type="submit" data-toggle="tooltip" title="Verwijder" onclick="return confirm('Weet je zeker dat je dit document wilt verwijderen')"><i class="fa fa-times"></i></button>
</form>
But yet it links to a different controller. What am I doing wrong?
I also specified the controller in the routes file:
Route::resource('document', 'DocumentController');
To add more context: this view gets passed from a different controller than I want to use for the DELETE function.
EDIT
I used a form inside another form, my stupid head didn't see it.
for deleting you can try this
<form action="{{action('DocumentController#destroy', $d->id)}}" method="post">
{{csrf_field()}}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
and Destroy method
public function destroy($id)
{
$doc= Document::find($id);
$doc->delete();
return redirect('/home')->with('success', 'Document has been deleted!!');
}

laravel delete method not working

I've made a small laravel project but the delete method is nog working:
I use a resource controller
my route is :
Route::resource('roles','Admin\RoleController');
in my view I have
<form action="{{route('roles.destroy',$role->id)}}" style="display:inline">
#method('delete')
#csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
But when i click the button it will show me the role ( = get method of the resource )
What am I doing wrong ?
If you're using Laravel 5.1 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
If you're using Laravel 5.6 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
You can read more about method spoofing in Laravel Documentation.
Check Laravel's documentation.
Did you try adding method="POST" to the form?

Laravel Eloquent to php

How to make delete function in laravel model, usually when in blade we use :
<form action="{{ action('ItemNameController#destroy', $ItemName->id) }}" method="post">
#csrf
#method("DELETE")
<input type="submit" class="btn btn-danger btn-sm btn-style" href="{{ $ItemName->id }}" value="Delete" onclick="return confirm('Are You Sure To Delete This Item? #{{ $ItemName->inc }} ')">
</form>
So how to write that code when we write it in controller, because in controller cannot to write eloquent or cannot to process (.blade.php)
Example in Controller:
foreach ($i as $value) {
echo "<form action='' method='post'>";
echo "<th><input type='submit' class='btn btn-danger btn-sm btn-style' href=' value='Delete' value='Delete' style='font-size: 10px'></th>";
echo "</form>";
}
You can achieve a this by:
<form action="{{ action('ItemNameController#destroy', $ItemName->id) }}" method="post">
{{csrf_field()}}
<input type="submit" class="btn btn-danger btn-sm btn-style" href="{{ $ItemName->id }}" value="Delete" onclick="return confirm('Are You Sure To Delete This Item? #{{ $ItemName->inc }} ')">
</form>
Where in your controller you would handle the delete method. If you were using an ajax request you could send a delete request to the server.
Your route something like be:
Route::post('/itemname/{ItemName}/delete', 'ItemNameController#destroy');
To stop it being confused with:
Route::post('itemname/{ItemName}', 'ItemNameController#update);
Hope this helps.

Laravel 5.2 - Form do not submit

Sorry, i'm very new to Laravel, i have this form:
<form action="/register" method="post">
{!! csrf_field() !!}
....
<div class="form-group">
<button type="button" class="btn btn-default">Register</button>
</div>
</form>
And the route is:
Route::get('/register', 'Auth\AuthController#getRegister');
Route::post('/register', 'Auth\AuthController#postRegister');
When i click on Register button nothing happen... the form do not submit, no errors etc.
Can you help me ?
Change this
<button type="button" class="btn btn-default">Register</button>
to
<button type="submit" class="btn btn-default">Register</button>
and always use dynamic url so that when you deploy your app to server,then you get no error(s)
action="{{ url('/register') }}
Change the type of the button:
<button type="submit"

Resources