user9555022
user9555022

Reputation:

Check if object exists in if statement

How can I check if an attribute exists in an OR statement, then check in an IF statement if it is set?

    @if($counsellingSession->has_session_begun == 1 || !empty($thread->close_session == 1))
         disabled
    @elseif($loop->index > 7 && $data->payment_type == 'free')
         disabled
    @endif

Upvotes: 0

Views: 2066

Answers (3)

Ray A
Ray A

Reputation: 1341

can you use property_exists for example:

@if((property_exists($counsellingSession,"has_session_begun") && $counsellingSession->has_session_begun == 1) || (property_exists($thread,"close_session") && $thread->close_session == 1 ) )
         disabled
    @elseif($loop->index > 7 && $data->payment_type == 'free')
         disabled
    @endif

Upvotes: 0

ZeroOne
ZeroOne

Reputation: 9117

use isset maybe? it will check whether the object is exists or not or null value

@if(isset($thread->close_session) && $thread->close_session == 1)
@endif

Upvotes: 0

umefarooq
umefarooq

Reputation: 4574

try property_exist php function if it exist it will gives you true other wise false

property_exist($thread,'close_session')

read about property_exist

http://php.net/manual/en/function.property-exists.php

Upvotes: 2

Related Questions