Laravel url 파라미터 가져오기

lize·2023년 2월 22일
0

예시 URL

https://velog.io/write?no=1

방법

// 방법 1
@if( app('request')->input('no') ) on @endif


// 방법 2
{{ app('request')->input('no') ? 'on' : '' }}


// 출력하려면
{{  dd( app('request')->input('no') )  }}


// 비슷하지만 다른
{{ app('request')->input('no') ?? '값이 없으면 이것이 출력됌' }}

활용

파라미터가 있으면 on 클래스 추가

<section class="@if( app('request')->input('no') ) on @endif">
  ...
</section>

옆자리 과장님이 적어주신 메모

echo처럼 php 변수 값을 프린트할때

  • 문자로 {{ }}
  • HTML TAG 그대로 {!! !!}

    blade 문법을 사용할 때는 {} 생략

참고

https://stackoverflow.com/questions/31324801/lumen-get-url-parameter-in-a-blade-view

profile
웹퍼블리셔

0개의 댓글