javascript

Form태그로 PUT, PATCH ,DELETE 방식을 사용하기

  1. form태그에 put,patch,delete사용

    REST방식으로 API를 설계할때 GET, POST말고 PUT, DELETE를 써야하는데

    form 태그 method에 아무리 PUT,PATCH,DELETE 써봤자 GET방식으로 들어가는 문제가있음

    아래와 같이 처리하면 PUT , PATCH, DELETE를 사용가능함

    <form id="blogForm" action="/donggu/blog" method="POST" >
        <input type="hidden" name="_method" value="PUT"/>
    </form>
    
  2. 라라벨에서 put,patch,delete사용

    라라벨에서는 아래의 지시어와 같이 사용함

    {{-- <input type="hidden" name="_method" value="PATCH"/> --}}
    @method('PATCH')
    
  3. form태그에 대해서 기억할 내용

    form안에 버튼의 타입은 submit, reset, button이 있다

    아무것도 안적으면 디폴트로 submit이다

    <form>
    <button type="submit">
    </form>
    
    // 보통 이런 형식
    <form>
      <label>
      <input type=..>
      <button type=..>
    </form>
    

참조

https://donggu1105.tistory.com/61

https://365kim.tistory.com/64