Ich habe eine Schaltfläche zum Löschen neben meinen Projekten, die ein Popup-Modal für die Bestätigung zeigt, wann immer auf die Schaltfläche geklickt wird. Ich möchte die Ja-Taste im Modal, um dann das Projekt zu löschen, wenn diese Schaltfläche angeklickt wird.Projekt mit Modal in Laravel löschen
Ich rufe das Modal in die Projekte/Show-Ansicht mit @include. Das Modal wird angezeigt, wenn auf die Schaltfläche mit der folgenden Abfrage geklickt wird, aber die Schaltfläche "Ja" beim Klicken das Projekt nicht löscht.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".delete").on("submit", function(e){
e.preventDefault();
$('#myModal').modal('show');
});
});
die Schaltfläche Löschen neben Projekten:
{!! Form::open(['route' => ['projects.destroy', $projects->id], 'class' => 'delete', 'method' => 'DELETE']) !!}
{!!Form::button('<span class="glyphicon glyphicon-remove"></span>', ['class' => 'btn btn-danger btn-md', 'type' => 'submit'])!!}
{!! Form::close() !!}
Modal Code:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title text-center" id="myModalLabel">Delete Confirmation</h4>
</div>
<div class="modal-body text-center">
Are you sure you want to delete this project?
</div>
<div class="modal-footer">
<button type="submit" id="delete-btn" class="btn btn-default" >Yes</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
ProjectController:
<?php
namespace App\Http\Controllers;
use App\project;
use App\Http\Requests;
use Illuminate\Http\Request;
use Session;
class ProjectsController extends Controller
{
public function destroy($id){
$project = Project::find($id);
$project->delete();
Session::flash('success', 'The project was successfully deleted!');
return redirect()->route('projects.show', $project->project_id);
}
}
Was genau ist das Problem? – Loek
Das Problem ist, wenn ich auf den Ja-Knopf im Modal klicke, tut es nichts und ich schaue auf diesen Knopf, um das Projekt zu löschen. – steven
Sie verweisen auf eine Route "projects.destroy", was macht diese Route? – Loek