简体   繁体   中英

if statement on blade laravel

There's 2 buttons on my blade like this :

<a data-url="{{route('trip.out', ['trip' => $trip->id])}}" data-table-name="#dataTable" class="btn btn-lg btn-primary out">Set - Out</a>
<a data-url="{{route('trip.completed', ['trip' => $trip->id])}}" data-table-name="#dataTable" class="btn btn-lg btn-primary completed">Set - Complete</a>

@push('custom_js')
<script type="text/javascript">
$(document).ready(function() {
$('a.out, a.completed').click(function(e) {
    $.redirect($(this).data('url'), {
        _token : '{{ csrf_token() }}',  
    }, 'POST');
})
});
</script>
@endpush

the one I want is once I click complete it return finish button, so i put this :

@if ($trip->id == 1)
<a href="javascript:;" class="btn btn-danger btn-xs">Finish</a>;
@endif

it doesn't work. Note out = 0, complete = 1 . status updated on database but it didn't return finish button.

any idea about the problem?

Problem may be due to this..

href="javascript:;"

SO change it as

@if ($trip->id == 1)
    <a href="javascript:void(0)" class="btn btn-danger btn-xs">Finish</a>;
@endif

When the html have generated with the laravel php, there is no ralations with the blade code.

The blade if is the server code, have nothing todo with you client button click.

If you want to do that, use client js code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM