Retrieving a message from a cryptocurrency daemon The objective of this piece of code is to get a message from a cryptocurrency daemon through RPC and extract the transactions object to pass it to the view. Is there a simpler / less ugly way of doing this?

$transaction_pool = json_decode($rpc-&gt;getTransactionPool(), false);

if(isset($transaction_pool-&gt;transactions)){
    $transaction_pool = $transaction_pool-&gt;transactions;
}else{
    $transaction_pool = (object)NULL;
}


View partial:   

@forelse ($transaction_pool as $transaction)
&lt;?php $transaction_json = json_decode($transaction-&gt;tx_json); ?&gt;
    &lt;div class="row show-grid top-row"&gt;
        &lt;div class="col-xs-12 col-sm-12 col-md-7"&gt;{{ $transaction-&gt;id_hash }}&lt;/div&gt;
        &lt;div class="col-xs-12 col-sm-7 col-md-5 pull-right"&gt;
        @if ($transaction_json-&gt;version == 2)
            &lt;div class="col-xs-7 col-md-6"&gt;&lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;&amp;nbsp;confidential&lt;/div&gt;
        @else
            &lt;div class="col-xs-7 col-md-6"&gt;@coin($transaction_json-&gt;amount)&lt;/div&gt;
        @endif
            &lt;div class="col-xs-5 col-md-6"&gt;@coin($transaction-&gt;fee)&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    @empty
    &lt;div class="row show-grid top-row"&gt;
        &lt;div class="col-xs-12"&gt;No transactions&lt;/div&gt;
    &lt;/div&gt;
@endforelse




&lt;div class="panel-heading large"&gt;
    Transactions ({{ count($transaction_pool) }})
&lt;/div&gt;
I don't get the point where you cast null to object.

I'm not sure what are you trying to achive,
but you can always make if 'less ugly'.

$transcations_pool = json_decode($rpc-&gt;getTransactionPool(), false);   
$transactions_pool = isset($transactions_pool-&gt;transactions) ? 
                         $transaction_pool-&gt;transactions : 
                         (object) null;


Also i would move div .show-grid to separate file and load it like this:

@include('path/to/file', [ 'transaction_json' =&gt; json_decode($transaction-&gt;tx_json) ])


Or you can implement special method like $transaction-&gt;decodeTxJson() to handle this decoding in $transaction class.