if condition in laravel according to database columns - laravel-5

I have a day column in a database and I want to display the other columns according to the day.
#foreach($specialism as $item)
#if($item->day ==="saturday")
<td>
<a class="btn btn-primary btn-lg" href="{{url('button',['id'=>$item->id])}}">
{{$item->name}}<br>
{{$item->day}}<br>
{{$item->from}}<br>
{{$item->to}}
</a>
</td>
#elseif($item->day === "sunday")
<td>
<a class="btn btn-primary btn-lg" href="{{url('button',['id'=>$item->id])}}">
{{$item->name}}<br>
{{$item->day}}<br>
{{$item->from}}<br>
{{$item->to}}
</a>
</td>
#elseif($item->day === "monday")
<td>
<a class="btn btn-primary btn-lg" href="{{url('button',['id'=>$item->id])}}">
{{$item->name}}<br>
{{$item->day}}<br>
{{$item->from}}<br>
{{$item->to}}
</a>
</td>
But it doesn't work. What's the problem??

You should sort the data before you get to the foreach loop and then just echo out the html.
If you use a date field with a carbon instances you also have a nummeric representation of the weekday so you could use that, like:
$collection->sortBy(function($a, $b){
return $a->date->day <=> $b->date->day; // date === carbon instance
});
If you only have a string representation you should get the weekday number by using either Carbon or PHP date, strtotime or DateTime and generate the number.
https://carbon.nesbot.com/docs/#api-getters

Related

Display data using pivot table

I have 2 tables which users and groups and I also has created a pivot table for them.
What I want to display is list of the group that user have not joined yet.
my controller
public function redirectFunct()
{
$user = User::find(Auth::user()->id);
$groups=Group::all();
$exists = DB::table('group_user')
->whereuser_id(Auth::user()->id)
->count() > 0;
return view('member.dashboard',['user'=>$user,'groups'=>$groups,'exists'=>$exists]);
}
blade file
#foreach($groups as $groups)
#if($!exists)
<tbody>
<tr>
<td>{{$groups->id}}</td>
<td>{{$groups->groupName}}</td>
<td>{{$groups->groupDesc}}</td>
<td><button type="button" class="btn btn-primary .btn-{color}">Details</button></td>
<td><a href="{{url('/join',$groups->id)}}"><button type="button" class="btn btn-secondary .btn-{color}">Join</button></td>
</tr>
</tbody>
#endif
#endforeach
I do not sure how to check if the data is exist or not in the pivot table. Please help me.
you could try this in your $exist I'm not sure what ->count() > 0; is use for
$exists = DB::table('Group')
->where('userID', Auth::user()->id)
->get();
If you want to display only the group that the user doesn't exist in group you could try this
<tbody>
#foreach($groups as $group)
#if('your group parent id' != 'your user id that related to the group')
<td>{{$group->id}}</td>
<td>{{$group->groupName}}</td>
<td>{{$group->groupDesc}}</td>
<td><button type="button" class="btn btn-primary .btn-{color}">Details</button></td>
<td><a href="{{url('/join',$groups->id)}}"><button type="button" class="btn btn-secondary .btn-{color}">Join</button></td>
#endif
#endforeach
</tbody>
this is the screenshot of that page
The pivot table

How to add number_format decimal in laravel in html view?

does anyone know how to add the decimal number_format here?, I don't use the blade from Laravel but I route the view directly to html... so if I add the number_format attribute, I'm confused ;(
<tr dir-paginate="income in incomes | filter:searchText | itemsPerPage:20" total-items="totalItems">
<td>{{income.incomeTitle}}</td>
<td>{{income_cat[income.incomeCategory]}}</td>
<td>Rp.{{income.incomeAmount}}</td>
<td>{{income.incomeDate}}</td>
<td>{{income.incomeNotes}}</td>
<td>
<a ng-show="income.incomeImage != ''" target="_blank" href="{{'index.php/incomes/download/'+income.id}}"><button type="button" class="btn btn-success btn-circle" title="{{phrase.Download}}" tooltip><i class="fa fa-cloud-download"></i></button></a>
<button ng-show="$root.can('Incomes.editIncome')" ng-click="edit(income.id)" type="button" class="btn btn-info btn-circle" title="{{phrase.Edit}}" tooltip><i class="fa fa-pencil"></i></button>
<button ng-show="$root.can('Incomes.delIncome')" ng-click="remove(income,$index)" type="button" class="btn btn-danger btn-circle" title="{{phrase.Remove}}" tooltip><i class="fa fa-trash-o"></i></button>
</td>
</tr>

Undefined variable in displaying values of index controller

I am new to Laravel, I know I'm just missing out on something yet I cant seem to find it.
I am sending compact('tabletinfo') from my controller index to home.blade.php under tablet folder yet my home.blade.php can't seem to find tabletinfo variable.
Here's the code for index controller.
public function index()
{
$tabletinfo = Tablets::all();
return view ('tablet.home', compact('tabletinfo'));
}
CODE FOR home.blade.php
<tbody>
#foreach ($tabletinfo as $tablet)
<tr>
<td>{{$tablet->owner_name}}</td>
<td>{{$tablet->owner_address}}</td>
<td>
<button class="btn btn-success" type="button" data-toggle="modal" data-target="#viewModal">View Details</button>
<button class="btn btn-info edit" type="button" data-toggle="modal" data-target="#editModal">Edit Details</button>
<button class="btn btn-danger" type="button">Delete</button>
</td>
</tr>
#endforeach
</tbody>
I guess my main problem is my view can't get the tabletinfo variable from my index controller.
there is a mistake. you write tablets instead of tablet
return view('tablet.home',compact('tabletinfo));
Can you please try this one ?
return view('tablet.home')->with('tabletinfo',$tabletinfo);
Or you can use this like
return view('tablet.home',compact['tabletinfo']);

RobotFramework : How to get information using 'following-sibling'

I want to recover the value of the account status "RF-Account" as shown in the picture.
For this, I target an xpath to retrieve the value just to the right of it with this code in RobotFramework :
${initialStatus}= Get Value //td[text()='${testAccount}']/following-sibling::span[#style=""]
Here is the html code of the information to retrieve:
<span class="text-bold ng-binding text-green" ng-class="{'text-green' : tenant.status == 'ACTIVE', 'text-muted' : tenant.status == 'INACTIVE'}" style="">ACTIVE</span>
And the html snippet that contains whole table :
<tbody ng-if="!isEmpty" class="body-table ng-scope" style="height: 193px;">
<!-- ngRepeat: tenant in tenants track by $index --><tr ng-repeat="tenant in tenants track by $index" class="ng-scope" style="">
<td class="ng-binding">RF-Accoun</td>
<td>
<span class="text-bold ng-binding text-green" ng-class="{'text-green' : tenant.status == 'ACTIVE', 'text-muted' : tenant.status == 'INACTIVE'}">ACTIVE</span>
</td>
<td style="width:118px">
<div class="pull-right">
<a name="editBtn" type="submit" class="btn-icon" ng-click="openCreateEditModal(tenant)">
<span class="icon-i-edit fs"></span>
</a>
<a name="deleteBtn" type="submit" class="btn-icon" ng-click="deleteTenant(tenant)">
<span class="icon-i-trash fs"></span>
</a>
</div>
</td>
</tr><!-- end ngRepeat: tenant in tenants track by $index --><tr ng-repeat="tenant in tenants track by $index" class="ng-scope">
<td class="ng-binding">RF-Account</td>
<td>
<span class="text-bold ng-binding text-green" ng-class="{'text-green' : tenant.status == 'ACTIVE', 'text-muted' : tenant.status == 'INACTIVE'}">ACTIVE</span>
</td>
<td style="width:118px">
<div class="pull-right">
<a name="editBtn" type="submit" class="btn-icon" ng-click="openCreateEditModal(tenant)">
<span class="icon-i-edit fs"></span>
</a>
<a name="deleteBtn" type="submit" class="btn-icon" ng-click="deleteTenant(tenant)">
<span class="icon-i-trash fs"></span>
</a>
</div>
</td>
</tr><!-- end ngRepeat: tenant in tenants track by $index --><tr ng-repeat="tenant in tenants track by $index" class="ng-scope">
<td class="ng-binding">RF-Account-bis</td>
<td>
<span class="text-bold ng-binding text-green" ng-class="{'text-green' : tenant.status == 'ACTIVE', 'text-muted' : tenant.status == 'INACTIVE'}">ACTIVE</span>
</td>
<td style="width:118px">
<div class="pull-right">
<a name="editBtn" type="submit" class="btn-icon" ng-click="openCreateEditModal(tenant)">
<span class="icon-i-edit fs"></span>
</a>
<a name="deleteBtn" type="submit" class="btn-icon" ng-click="deleteTenant(tenant)">
<span class="icon-i-trash fs"></span>
</a>
</div>
</td>
</tr><!-- end ngRepeat: tenant in tenants track by $index -->
</tbody>
It doesn't work. Could you, please, correct me for it to work ?
First, you should use keyword Get Text, because Get Value return value attribute of element. In your case your element do not have this attribute, so I assume that you want text.
Second, span elements from html snippet containing whole table differ from span element that your provided separately. They do not contain style attribute.
Finally the most probable solution to your problem is:
Get Text //td[text()='${testAccount}']/following-sibling::td/span

Laravel 5.4, user cannot see dashboard if they don't own anything

The problem is, is that when I sign a new user up (in my application a 'charity owner'), they are redirected to their dashboard.
On the dashboard, displays the all the charities that the user owns and any donations made to them in another table.
However, because the user has not added their charity to the database yet I am getting undefined variables.
#forelse($ownedCharities as $owned)
<td> {{ $owned->name }} </td>
<td> Not Available </td>
<td> <p id="desc"> {{ $owned->description }} </p> <p style="color: #000;" class="seeMore"> See more... </p> </td>
<a href="#"> <button class="btn btn-danger btnPopover"
data-toggle="popover" data-placement="top"> Delete </button> </a> </td>
<td> <button class="btn btn-warning"> Edit </button> </td>
</tr>
#empty
<p> No charities owned </p>
#endforelse
I am using Blade's #forelse
You can use php functions in blade like to see if they are or not defined or has some value
#isset($records)
// $records is defined and is not null
#endisset
#empty($records)
// $records is "empty"...
#endempty
You can use Null coalescing operator which is introduces in PHP 7
$records ?? ""

Resources