How to add delete confirmation in laraadmin modules? - laravel

I am using laraadmin in one of my application but module generated by admin not confirming when deleting any record. Please some one help me How to add delete confirmation in laraadmin modules?

I do not know how to work with laraadmin but You can do that by java script:
Blade:
#foreach (items as item)
<form class="delete" action="{{ route('item.destroy', $item->id) }}" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="submit" value="Delete">
</form>
#endforeach
JS:
<script>
$(".delete").on("submit", function(){
return confirm("Do you want to delete this item?");
});
</script>
And if you need preety nice confirmation design You can use Sweet Alert JS Library:
https://sweetalert.js.org/guides/

Related

MJML converts links in email clients to mjt.lu

Laravel-mix-mjml plugin converts href links. All links work fine except one link which is a form with post request. It doesn't pass the parameters. In the browser the links are not converted. How can I fix this? Thanks
<mj-text>
<form action="https://www.carsale.com/login" method="post" target="_blank">
<input type="hidden" name="customerId" value="{{ $inquiry->customer->customer_id ?? '' }}">
<input type="hidden" name="authToken" value="{{ $inquiry->customer->auth_token ?? '' }}">
<button type="submit" name="submit">Lets go</button>
</form>
Lets go
</mj-text>

laravel 7 - unable to pass input parameter to form action for searching purpose

how i can pass input value form action and replace number 5? the below works if i put numbers only, then it pass it to route then controller:
<!--Search to mysql -->
<form action="{{ route('propertyname.show', 5)}}" method="GET" role="search">
#csrf
<Label for="id">search:</Lebal>
<input type="text" id='id' name="id" placeholder="Search plzz">
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
<input type="submit" name="submit" value="Serach">
</form>
Route::get('/property_name/{id}','RsmsController#show')->name('propertyname.show');
the above works if I typed number 5 manually which I don't want, I want it to read\input from FORM TEXT and fired when clicking on the form button to send the value to the controller.
http://127.0.0.1:8000/property_name/5
enter image description here
You can take a look at simple jQuery on click/submit method.
$(function() {
$("#myform").submit(function(e) {
var actionUrl = "{{ url('/property_name/') }}" + $("#id").val();
$(this).attr("action", actionUrl);
});
});

Laravel datatables raw columns

i have a code like this to display an action button for datatables
->addColumn('action', function () {
return '<form id="delete" action="{{ route(' . 'admin.posts.destroy' . ', $model) }}" method="POST">
#csrf
#method("DELETE")
Edit
<input type="submit" class="btn btn-danger" value="Delete">
</form>';
})
But the #csrf and #method("DELETE") become a string/text (not method). I tried to append {{ }} in #csrf and #method("DELETE") but it doesn't work. How to change that text to method in blade templates without make a new view for action button like that?
Thank you!
#csrf replace with <input type="hidden" name="_token" value="{{ csrf_token() }}"> and
#method("DELETE") with <input type="hidden" name="_method" value="delete">

form displaying in controller popup

i make form that i want to link in with controller called companies controller but i add form code inside the list it show the whole code ink the web page
<li>
<a href="#" onclick="
var result = confirm('are you sure you want to delete this project?');
if(result){
event.preventDefault();
document.getElementById('delete-form').submit();
}
">
Delete
</a>
<form id="delete-form" action="{{ route('companies.destroy',[$company->id]) }}" method="post" style="display:none;">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
</form>
</li>
in the web page only the delete should visible in the section not other part of the code
first of all, separate your code of javascript from html so that it be understandable and also easy to debug. try this:
<li>
Delete
<form id="delete-form" action="{{ route('companies.destroy',[$company->id]) }}" method="post" style="display:none;">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
</form>
</li>
<script type="text/javascript">
function delete()
{
var result = confirm('are you sure you want to delete this project?');
if(result){
event.preventDefault();
document.getElementById('delete-form').submit();
}
}
</script>
Found some typos which I corrected, maybe that was the issue. Also, you could very well send an ajax instead of submitting a hidden form, just an idea.

MethodNotAllowedHttpException Laravel method PUT not working

Basically I am using modal-dialog as shown below and I'm trying to get the method PUT to work. Unfortunately, I've tried either ways with _method="PUT" but it still doesn't work, anyone has a solution for this?
<div class="modal-body">
<form class="form-horizontal" role="form" method="POST" _method="PUT" action="/manage_accounts/{{ $user->id }}" novalidate>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
The problem is that HTML does not support PUT methods natively so you can't do something like this:
<form method="PUT"...
There is a workaround for this. Laravel accepts PUT, PATCH, and DELETE methods by adding a hidden input field. In other words, something like this:
<form class="form-horizontal" role="form" method="POST" action="/manage_accounts/{{ $user->id }}" novalidate>
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Notice that you are POSTing to the server, but you can add a hidden input field named _method for PUT, PATCH, and DELETE methods.
You are probably PUTting to a GET route.
Make sure that the '/manage_accounts/{id}' route is setup as a PUT in your routes file.
Route::put('/manage_accounts/{id}', function()
{
//
});

Resources