I am trying to write some code inside a laravel blade as shown below
#can('identical_trademark_local_show')
#php
$trimmed_payment_id=Str::substr($Payment->payment_id,0,9);
if($trimmed_payment_id=='AlYAFI:IL')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.identical-trademark-locals.show', $Payment->id) }}">
trans('global.view')
</a>"
}
if($trimmed_payment_id=='AlYAFI:SL')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarlocals.show', $Payment->id) }}">
trans('global.view')
</a>
}
if($trimmed_payment_id=='AlYAFI:SI')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarinternationals.show', $Payment->id) }}">
trans('global.view')
</a>
}
#endphp
#endcan
The problem is that am getting a syntax error
syntax error, unexpected '<'
You can't use the mustache {{ }} symbol inside a #php block and you need to write your HTML code outside of your #php block
You'd be better off writing everything in blade syntax, one of the way to do it is as follow:
#can('identical_trademark_local_show')
#php
$trimmed_payment_id=Str::substr($Payment->payment_id,0,9);
#endphp
#if($trimmed_payment_id=='AlYAFI:IL')
<a class="btn btn-xs btn-primary" href="{{ route('admin.identical-trademark-locals.show', $Payment->id) }}">
trans('global.view')
</a>
#endif
#if($trimmed_payment_id=='AlYAFI:SL')
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarlocals.show', $Payment->id) }}">
trans('global.view')
</a>
#endif
#if($trimmed_payment_id=='AlYAFI:SI')
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarinternationals.show', $Payment->id) }}">
trans('global.view')
</a>
#endif
#endcan
NOTE
You should avoid the #php block and instead pass on the value from your controller.
Related
Hello i have a problem in my code to show a detail from data-tables, the error say "Missing required parameter for [Route: rekap.laba] [URI: rekapan/laba1/{tanggal}] [Missing parameter: tanggal]"
i don't know how to fix it,
this is the button blade
<a href="{{ route('rekap.laba', $penjualan->tanggal) }}" id="detail" class="btn btn-sm btn-info" data-tooltip="tooltip"
data-placement="bottom" title="Detail Laba" ><i class="fa fa-info-circle"></i></a>
this is theroute
Route::get('rekapan/laba1/{tanggal}', '\App\Http\Controllers\TransaksiController#labaReport')->name('rekap.laba')->middleware('admin');
this is the controller
public function labaReport($tanggal)
{
$transaksis = Transaksi::leftJoin('produks', 'produks.id', '=', 'transaksis.produk_id')
->leftJoin('daftar_pelanggans', 'daftar_pelanggans.id', '=', 'transaksis.daftar_pelanggan_id')
->select('transaksis.daftar_pelanggan_id', 'produks.harga_jual', 'produks.harga_beli', 'produks.nama_barang', 'produks.kode_barang', 'transaksis.kode_transaksi', 'transaksis.total_barang', 'transaksis.created_at', DB::raw('sum(total_barang) as total_beli'), DB::raw('count(produk_id) as produklist'))
->groupBy('transaksis.kode_transaksi', 'produks.harga_jual', 'transaksis.created_at', 'produks.harga_beli', 'produks.nama_barang', 'produks.kode_barang', 'transaksis.total_barang', 'transaksis.daftar_pelanggan_id')
->where(DB::raw('DATE(transaksis.created_at)', '=', $tanggal))
->get();
return view('pages.rekapan.keuntungan', compact('transaksis'));
}
to correctly add the parameter, change:
<a href="{{ route('rekap.laba', $penjualan->tanggal) }}" id="detail" class="btn btn-sm btn-info" data-tooltip="tooltip"
data-placement="bottom" title="Detail Laba" ><i class="fa fa-info-circle"></i></a>
to:
<a href="{{ route('rekap.laba', ['tanggal' => $penjualan->tanggal]) }}" id="detail" class="btn btn-sm btn-info" data-tooltip="tooltip"
data-placement="bottom" title="Detail Laba" ><i class="fa fa-info-circle"></i></a>
Note that if $penjualan->tanggal is null it will also throw that error.
I want to disable the delete post button inside in post foreach blade laravel . where post has created_at in database , i want the " delete post button" get disable after 15 days
i tried with some javascript tutorials but i couldn't achieve that thing
Can anyone please help me.it would be much appreciated if you could help me
thanks in adavance
<table id="" class="table ">
<thead>
<tr class="data-item master">
<th>Name</th>
<th>post</th>
<th>about</th>
<th>image</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach($data as $d)
<tr>
<td>{{$d->name}}</td>
<td>{{$d->postbody}}</td>
<td>{{$d->about}}</td>
<td>{{url($d->image)}}</td>;
<td><a href="{{ URL::to('edit/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="edit">
<i class="fa fa-edit">edit post</i></a>
</td>
<td><a href="{{ URL::to('delete/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
</td>
</tr>
#endforeach
</tbody>
</table>
You can not disable an anchor tag but you can change the URL to # as dummy url
#if(\Carbon\Carbon::parse($d->created_at)->addDays(15) < \Carbon\Carbon::now())
<a href="#"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#else
<a href="{{ URL::to('delete/product/'.$d->id) }}"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#endif
It's simple use and conditional statement on the disable attribute.
Something like This
<button class="anyClass" {{ Carbon::addDays(15)->greaterThan($post->created_at) ? 'disable' : ' }}>Delete</button>
I think something like this will work
I want to do the following in my blade.php but I get a syntax error:
<a class="btn btn-info" role="button" href="{{ url('/Animal/{{$animal->id}}/edit')}}">Edit Profile</a>
The error is to do with the href attribute I think, how do I correct the syntax?
Error I am getting:
enter image description here
You have an error in your code, please try this one.
<a class="btn btn-info" role="button" href="{{ url('/Animal/' . $animal->id . '/edit')}}">Edit Profile</a>
Hope this helps.
Yes you have a syntax error in your code. You can't use {{ }} inside another {{ }}.
You have access to php variable inside this first {{ }}.
Use "" instead of '' to use php variables inside a string.
<a
class="btn btn-info"
role="button"
href="{{ url("/Animal/$animal->id/edit") }}"
>
Edit Profile
</a>
I'm trying to write an if-else loop: if there is an embed saved in the database it should display a calendar, if not it should display a button saying "add new calendar/add new embed", but it's not working. I can't figure out why. When there is an embed saved in the database it displays the embed but, if there isn't an embed it doesn't display the button to add a new calendar/embed:
Blade view:
#if (empty($calendars))
#else
<h4>No calendar settings</h4><br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button">
<i class="fa fa-cloud-upload"></i>
<span class="bold">Add embed</span>
</button>
</a>
#endif
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
Controller:
public function kalendarz() {
$calendars = Calendar::with('users')->where('user_id', Auth::user()->id)->get();
return view('kalendarz',['calendars'=>$calendars]);
}
In Laravel 5.4, I would probably use the #unless blade directive, that will show the block, unless a condition is met. What the following code would acheive is "show the entries if we have some, and show the button unless we have some entries".
#if($calendar)
// show entries
#endif
#unless(empty($calendars))
// show a button to add a new one
#endunless
It kind of is the same "logic" as with an else, but somehow I think it's more clear and easy to read than an #else statement, and make it separate from the if.
The correct syntax is:
#if(empty($calendars))
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span></button>
</a>
#else
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
#endif
empty() functions empty the variable $calendars, so try using count()
#if(count($calendars) > 0)
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}">
<button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span></button>
</a>
#else
#foreach($calendars as $calendar)
{{ $calendar->embed }}
#endforeach
#endif
When using Eloquent to get results from a database you get an instance of Illuminate\Database\Eloquent\Collection. To check if that collection is empty you use $collection->isEmpty() or $collection->isNotEmpty() (L5.4).
#if ($calendars->isNotEmpty())
// Have entries.
#else
<h4>No calendar settings</h4></br>
<a href="{{ route('calendarsettings.create')}}"><button class="btn btn-success btn-cons m-b-10" type="button"><i class="fa fa-cloud-upload"></i> <span class="bold">Add embed</span>
</button></a>
#endif
#foreach($calendars as $calendar)
{{$calendar->embed}}
#endforeach
My view contains the following code
#foreach ($building as $maps)
<div class="btn-group">
<a class="btn btn-primary" role="button" href="{{ URL::asset('floorPlans/$maps') }}" aria-expanded="false" aria-controls="collapseExample">
{{ $x }}
</a>
</div>
<?php $x++; ?>
#endforeach
Yet this is resulting in the follwoing HTML
<div class="btn-group">
<a class="btn btn-primary" role="button" href="http://facilities-lara.hslc.wisc.edu/floorPlans/$maps" aria-expanded="false" aria-controls="collapseExample">2</a>
</div>
With $maps still being appended to URL instead of the value within $maps. Is it possible to retrieve the value within a blade template?
Thanks,
Otterman
Everything between the blade tags is just normal PHP. So you can simple concatenate the string and the variable:
{{ URL::asset('floorPlans/'.$maps) }}