2017-05-07 2 views
0

내가 PHP를 laravel 코딩에서 초보자 도와주세요 해요laravel의 확인 삭제

내가 laravel 5.3을 사용하고 난 사용에 의해 삭제하려면 확인이 이미 저점을 설치 한

을 SweetAlert 만들고 싶어 "npm install" 및 이미 node_modules 폴더에 있습니다.

이 모듈을 사용하려면 다음 질문을해야합니다.

는 기능 등과 같은 준비가 자바 스크립트 함수

/** 
* Allows you to add data-method="METHOD to links to automatically inject a form 
* with the method on click 
* 
* Example: <a href="{{route('customers.destroy', $customer->id)}}" 
* data-method="delete" name="delete_item">Delete</a> 
* 
* Injects a form with that's fired on click of the link with a DELETE request. 
* Good because you don't have to dirty your HTML with delete forms everywhere. 
*/ 
function addDeleteForms() { 
    $('[data-method]').append(function() { 
     if (! $(this).find('form').length > 0) 
      return "\n" + 
       "<form action='" + $(this).attr('href') + "' method='POST' name='delete_item' style='display:none'>\n" + 
       " <input type='hidden' name='_method' value='" + $(this).attr('data-method') + "'>\n" + 
       " <input type='hidden' name='_token' value='" + $('meta[name="_token"]').attr('content') + "'>\n" + 
       "</form>\n"; 
     else 
      return ""; 
    }) 
    .removeAttr('href') 
    .attr('style', 'cursor:pointer;') 
    .attr('onclick', '$(this).find("form").submit();'); 
} 

예를 들어 elete 버튼에 addDeleteForms 아래 추가 처음

+1

삭제 버튼에 코드를 추가하여 사용 하시겠습니까? – ceejayoz

답변

1

을;

JS 코드

$('button#deleteButton').on('click', function(e){ 
var name = $(this).data('name'); 
e.preventDefault(); 
swal({ 
    title: "Careful!", 
    text: "Are you sure you want to delete "+name+"?", 
    icon: "warning", 
    dangerMode: true, 
    buttons: { 
     cancel: "Exit", 
     confirm: "Confirm", 
    }, 
}) 
.then ((willDelete) => { 
    if (willDelete) { 
     $(this).closest("form").submit(); 
    } 
}); 

});

보기에서 양식 내에 버튼을 만들고 삭제할 요소의 이름과 함께 data-name을 추가하십시오.

<button type="submit" id="deleteButton" data-name="{{ $model->name }}" class="btn btn-xs btn-danger">Delete</button> 
-1

감사 :이 사용하고있다

<a href="{{route('customers.destroy', $customer->id)}}" 
    data-method="delete" 
    data-trans-button-cancel="Cancel" 
    data-trans-button-confirm="Delete" 
    data-trans-title="Are you sure?" 
    class="btn btn-xs btn-danger"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="Delete"></i></a>