若字段为空,则Laravel


Laravel if field is empty

我是laravel 的新手

我有一个host-profile.blade.php,它有

<input type='text' name='cc_cvv' value='{{ $creditcard->card_cvv }}'>

我得到了UserController.php

public function host(){
$this->params['creditcard'] = Creditcard::where('user_id', '=', $user->id)->first();
return View::make('users.host-profile', $this->params);
}

问题是,如果我的表"creditcards"是空的/被截断的,因为它在其中找不到任何user_id,它就会抛出一个错误。我如何才能显示空的

Blade为这个用例提供了一个不错的or快捷方式。

{{ $creditcard->card_cvv or '' }}

这与相同

{{ isset($creditcard->card_cvv) ? $creditcard->card_cvv : '' }}