안녕하세요 변수가 이미 설정되어 있는지 또는 블레이드 버전을 사용하고 있지 않은지 확인하려고합니다. 그러나 원시 PHP는 작동하지만 블레이드 버전은 작동하지 않습니다**. 어떤 도움이 필요하신가요?
컨트롤러:
public function viewRegistrationForm()
{
$usersType = UsersType::all();
return View::make('search')->with('usersType',$usersType);
}
view:
{{ $usersType or '' }}
오류를 표시합니다:
정의되지 않은 변수: usersType (보기: C:\xampp\htdocs\clubhub\app\views\search.blade.php)
{{ $usersType 또는 '' }}
가 정상적으로 작동합니다. 여기서 문제는 포리치 루프입니다:
@foreach( $usersType as $type )
<input type="checkbox" class='default-checkbox'> <span>{{ $type->type }}</span>
@endforeach
이것을 @if()
에 넣는 것이 좋습니다:
@if(isset($usersType))
@foreach( $usersType as $type )
<input type="checkbox" class='default-checkbox'> <span>{{ $type->type }}</span>
@endforeach
@endif
를 사용할 수도 있습니다. 간단하고 쉽습니다.
@forelse ($users as $user)
<li>{{ $user->name }}</li>
@empty
<p>No users</p>
@endforelse
나는 해결을 사용하여 이것을선택()
helper. 예를 사용하여 여기에 그것이 될 것이다:
{{선택 사항($usersType)}}
더 복잡한 예로 들 수 있는 경우,다음과 같이 나,당신은에 액세스하려고 시설의 null 체(ie. $사용자->유형
)뷰에서 사용하는옛날()
helper.
value="{{올드('유형',옵션($사용자)->유형}}"
하는 것이 중요하 괄호 주위에 이동체 변수지 전체를 액세스하려면 시설의 개체입니다.
후 새로운 업데이트 php
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
체크인 ref:https://laravel-news.com/blade-templates-null-coalesce-operator