fico7489
fico7489

Reputation: 8560

Laravel: how to set checkbox to be checked on default?

How to set checkbox to be checked on default but use same form for create and edit ?

I have form :

{!! Form::model($product, ['route' => $formRoute, 'method' => $formMethod]) !!}

    {{ Form::checkbox('is_active') }}

{!! Form::close() !!}

and I want is_active to be checked on create, but load from $model on edit, if I put :

{{ Form::checkbox('is_active', 1, true) }}

it is checked on create, but is also checked on edit even if in db is unchecked (false).

I am looking for best solution...

Upvotes: 1

Views: 3258

Answers (1)

Sangar82
Sangar82

Reputation: 5230

Try this:

{{ Form::checkbox('is_active', 1, isset($product) ? true : false) }}

We are assuming that you have a $product var in your edit form

Upvotes: 2

Related Questions