Knox
Knox

Reputation: 81

Laravel if field is empty

I'm new to laravel

I have a host-profile.blade.php that has

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

and i got UserController.php

public function host(){

$this->params['creditcard'] = Creditcard::where('user_id', '=', $user->id)->first();

return View::make('users.host-profile', $this->params);

}

the thing is, it throws an error if my table 'creditcards' is empty/truncated because it cant find any user_id in it. How will i be able to show empty

Upvotes: 1

Views: 1399

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 153140

Blade has a nice or shortcut for this use case.

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

This is the same as:

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

Upvotes: 3

Related Questions