lundi 20 juin 2016

Default variable value in blade Laravel

How do I set a default value to a variable in a blade partial?

So for example I have 2 variables:

  • softDelete
  • delete

witch I want by default to be true.

@if($softDelete)
    <span data-toggle="tooltip" title="Publish">
        <a href="#delete-" class="btn btn-default btn-xs btn-flat">
            <i class="fa fa-check"></i>
        </a>
    </span>
@endif

@if($delete)
    <span data-toggle="tooltip" title="Delete">
        <a href="#delete-" class="btn btn-danger btn-xs btn-delete btn-flat details" data-toggle="modal" data-target="#delete_modal">
            <i class="fa fa-trash"></i>
        </a>
    </span>
@endif

And when I send the view from controller to change the value for some of the variables, depending the case I need.

return view('platform.pages.blocks.property_table_actions',
    [
        'id' => $model->id,
        'delete' => false
    ]);

I tried with a provider:

public function composeActionButtons()
{
    view()->composer('platform.pages.blocks.property_table_actions', function ($view) {
        $view
            ->with('softDelete', true)
            ->with('delete', true)
            ->with('view', true)
            ->with('edit', true);
    });
}

but override the false values from controller.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire