A non-numeric value encountered in Laravel script - php

In my Laravel script on a page this error appears:
"A non-numeric value encountered (View: /home/grammer/public_html/test/core/resources/views/admin/apiServices.blade.php)"
for this line
<td>{{ $key+1 }}</td>
my page codes:
#extends('admin.layouts.master')
#section('page_icon', 'fa fa-suitcase')
#section('page_name', 'API Services')
#section('body')
<div class="row">
<div class="col-md-12">
<div class="tile">
<h3 class="tile-title">API Services List</h3>
<table class="table table-hover">
<thead>
<tr>
<th>Serial</th>
<th>Service ID</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Min</th>
<th>Max</th>
</tr>
</thead>
<tbody>
#foreach($items as $key => $item)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ isset($item->service->id) ? $item->service->id : $item->service}}</td>
<td>{{ $item->name }}</td>
<td>{{ $item->category }}</td>
<td>{{ isset($item->rate) ? $item->rate : $item->price_per_k }} $</td>
<td>{{ $item->min }}</td>
<td>{{ $item->max }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#endsection

Just add this :
<td>{{ (int) $key + 1 }}</td>
or Add this:
$key = (int) $key; // GET NUMBER FROM VARIABLE

Related

Laravel pagination problem one by one pages

I'm sorry, I have a problem with my laravel pagination Gives me one by one page for example, in my table 16 row I make paginate (10), the pagination gives me in the first page from 1 to 10 and in the second page from 1 to 6 I want the normal pagination from 1 to 10 and from 11 to 16 any help, please
public function allappointmnts(){
$allapo=DB::table('bookappoitments')->orderBy('times.id')
->join('users','bookappoitments.users_id','users.id')
->join('times','bookappoitments.times_id','times.id')
->join('dates','bookappoitments.Dates_id','dates.id')
->paginate(10);
return view('admin.Managers.allappoinments',compact('allapo'));
}
in the blade page:
<div class="text-center">
{!! $allapo->links(); !!}
</div>
The table :
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td>{{ $loop->index+1 }}</td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td>
<a class="btn btn-success btn-mini deleteRecord " href="{{url('showbymanagment',$Appointments->id)}}">Show</a>
</td>
</tr>
#endforeach
Your problem is that you're using the current index of each loop - which will always be within the range of 1-10 of each page (since you have 10 elements per page).
You need to get the current page you're on using
$allapo->currentPage()
Then get the number of elements per page you got, using
$allapo->perPage()
Multiply these two, and it will be the base number for your pagination, meaning that its this number you should increment from.
The indexed table should then be
{{ $allapo->currentPage() * $allapo->perPage() + $loop->index }}
instead of
{{ $loop->index+1 }}
Then, to fix the heading-numbers (10 and 6 at the top), get the total number of results instead of the count of the page using
$allapo->total()
See the Laravel documentation for more details.
Not entirely sure, but you will need to write some sort of function to fix this.
Essentially you need to do this:
Get the page number (ex: 1)
Multiply it by the rows per page (ex: 10)
Add the iteration number
Subtract the per page number
function correct_pagination_numbers($cp, $pp, $counter)
{
$c = (($pp * $cp) + $counter) - $pp;
return $c;
}
Then you can call the function in your view like so:
<td>{{ correct_pagination_numbers($allapo->currentPage(), $allapo->perPage(), $loop->index) }}</td>
It would probably be the best solution to do this in a helper file. If you don't know how to create a helper file and autoload it, you can look here.
Try this code:
<?php $i = $lists->perPage() * ($lists->currentPage() - 1); ?>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td><?php $i++; ?>{{ $i }} </td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td><a class="btn btn-success btn-mini deleteRecord " href="
{{url('showbymanagment',$Appointments->id)}}">Show</a></td>
</tr>
#endforeach
Try ths
#foreach($allapo as $key => $Appointments)
{{ $key + $allapo->firstItem() }}
#endforeach
to see the correct number change the line
<td>{{ $loop->index+1 }}</td>
to:
<td>{{ ($allapo->currentPage() - 1) * $allapo->perPage() + $loop->iteration }} <td>

Foreach loop (laravel blade)

I need help with a foreach loop in laravel. For some reason I need to have two rows instead of two tables (would have solved my problem) However, I have problems with it getting to work due to not knowing where to place my tags to get the right table structure.
Code:
<table class="minimalistBlack">
<tbody>
<tr>
<th>Etternavn</th>
<th>Navn</th>
<th>Posthylle</th>
<th>X</th>
<th>Etternavn</th>
<th>Navn</th>
<th>Posthylle</th>
</tr>
#foreach ($data as $mailbox)
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
<td></td>
#endforeach
#foreach ($data2 as $mailbox)
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
#endforeach
</tbody>
</table>
How can I combine the two foreach loops and and get the right table structure?
to achieve just that result you could do
foreach (array_combine($courses, $sections) as $course => $section)
but that only works for two arrays
or u can use two table and make feel as single table
<div class="row">
<div class="col-md-6 col-sm-6">
<table class="table table-striped">
#foreach ($data as $mailbox)
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
<td></td>
#endforeach
</table>
</div>
<div class="col-md-6 col-sm-6">
<table class="table table-striped">
#foreach ($data as $mailbox)
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
<td></td>
#endforeach
</table>
</div>
Assuming the $data and $data2 variables are Laravel collection instances, you can simply use $data = $data->concat($data2). Now $data will contain data of both variables. For a simple array, you can use $data += $data2;. This will merge $data & $data2 to $data. Then you can simply use:
...
#foreach ($data as $mailbox)
<tr>
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
</tr>
#endforeach
</tbody>
</table>
User array_merge function in controller like this
$array1 = array("john","ny");
$array2 = array("mitchel","ny");
$result = array_merge($a1,$a2);
if $data and $data2 have one, one row you can try like this.
#foreach ($data as $mailbox)
<tr>
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
<td></td>
</tr>
#endforeach
#foreach ($data2 as $mailbox)
<tr>
<td>{{ $mailbox->last_name }}</td>
<td>{{ $mailbox->first_name }}</td>
<td>{{ $mailbox->row }}{{ $mailbox->number }}</td>
</tr>
#endforeach

JSON output to AngularJS parsejson

I cannot seem to put these into a scope.. And not sure if im doing something wrong...
HTML:
<div class="col-md-10 pull-md-left" style=" width:102%;">
<div class="row">
<span style="text-decoration:underline;">EC2 Instances</span> <span style="clear:both;">refresh</span>
<table class="table-striped" style="width:100%;border:1px solid gray;">
<thead>
<tr style="border-bottom:1px solid black; background-color:black; color:white;">
<th title="ID" style="width:20px;">#</th>
<th title="Customer Attached">Customer</th>
<th title="Instance Name">Name</th>
<th title="Instance ID">ID</th>
<th title="Instance Type">Type</th>
<th title="Instance Availability Zone">Zone</th>
<th title="This is Title">State</th>
<th title="Public DNS">WAN_DNS</th>
<th title="Public IP">WAN_IP</th>
<th title="What Instasnce Was Booted Up">Started</th>
<th title="Security Groups">Security</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ec2 in servers">
<td>{{ $index + 1 }}</td>
<td>{{ customerID }}</td>
<td>{{ instancename }}</td>
<td>{{ ec2.instanceID }}</td>
<td>{{ ec2.instanceType }}</td>
<td>{{ ec2.instanceAvailabilityZone }}</td>
<td>{{ ec2.instanceState }}</td>
<td>{{ ec2.publicdns }}</td>
<td>{{ ec2.publicip }}</td>
<td>{{ ec2.startdate }}</td>
<td>{{ ec2.secgroup }}</td>
</tr>
<tr ng-show="!ec2.length">
<td colspan="11" style="text-align:center;">
<BR>
No Instances have been syncronized.
<BR>
<BR>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
CONTROLLER:
<script>
var app = angular.module('myApp', []);
app.controller('ec2instanceCtrl', function($scope, $http) {
console.log('a test');
$http.get("ec2instances.php")
.then(function (response) {
$scope.servers = JSON.parse(response.data);
//$scope.servers = response.data.records;
$scope.servers = results[0].ec2instance.map;
}
);
});
JSON:
{
"ec2instance": [{
"ID": 0,
"customerID": null,
"ec2.instancename": "domain1.host",
"ec2.instanceID": "i...",
"ec2.instanceType": "x3large",
"ec2.instanceAvailabilityZone": "us-east-1a",
"ec2.instanceState": "running",
"ec2.publicdns": "..com",
"ec2.publicip": "127.0.0.1",
"ec2.startdate": "11\/25\/2016 1:30AM",
"ec2.secgroup": "open.ports"
}, {
"ID": 1,
"customerID": 2,
"ec2.instancename": "server.com",
"ec2.instanceID": "i2",
"ec2.instanceType": "x5large",
"ec2.instanceAvailabilityZone": "us-east-2c",
"ec2.instanceState": "running",
"ec2.publicdns": ".com",
"ec2.publicip": "125.5.5.5",
"ec2.startdate": "11\/1\/15 1:00am",
"ec2.secgroup": "all"
}]
}
Now just trying to figure out the results and why it's not populating.... I am having no luck, is it because the JSON isnt properly formatted? Or am I not setting the scope correct?
Any help much appreciated!
Do $scope.servers = JSON.parse(response.data).ec2instance, then $scope.servers should be an array containing your servers.
Assuming the parsed data is ok (try console.log($scope.servers) after the JSON.parse line), use the following notation in your ng-repeat instead:
<tr ng-repeat="s in servers">
<td>{{ $index + 1 }}</td>
<td>{{ s.customerID }}</td>
<td>{{ s.instancename }}</td>
<td>{{ s['ec2.instanceID'] }}</td>
<td>{{ s['ec2.instanceType'] }}</td>
<td>{{ s['ec2.instanceAvailabilityZone'] }}</td>
<td>{{ s['ec2.instanceState'] }}</td>
<td>{{ s['ec2.publicdns'] }}</td>
<td>{{ s['ec2.publicip'] }}</td>
<td>{{ s['ec2.startdate'] }}</td>
<td>{{ s['ec2.secgroup'] }}</td>
</tr>

Link of anchor tag is also printing in Laravel Blade

I have a table of employee's salary list. I wrap the employee id with an anchor tag to show salary history of each individual employees. The problem is when I print the table the link for individual salary history is also printed under the employee id.
Here is a screen shot print preview:
Blade
<div class="d-section col-md-12">
<table class="table table-striped table-condensed table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Start Date</th>
<th>End Date</th>
<th>Worked</th>
<th>Basic</th>
<th>OT Rate</th>
<th>OT Hour</th>
<th>OT Amount</th>
<th>Basic Amount</th>
<th>Total</th>
<th>Signature</th>
<th>Finger</th>
</tr>
</thead>
<tbody>
#foreach($employees as $employee)
<tr>
<td>{{ $employee->eid }}</td>
<td>{{ $employee->name }}</td>
<td>{{ $employee->designation }}</td>
<td>{{ $employee->start }}</td>
<td>{{ $employee->end }}</td>
<td>{{ $employee->worked }}</td>
<td>{{ $employee->basic }}</td>
<td>{{ $employee->ot_rate }}</td>
<td>{{ $employee->ot_hour }}</td>
<td>{{ $employee->ot_amount }}</td>
<td>{{ $employee->basic_amount }}</td>
<td>{{ $employee->ot_amount + $employee->basic_amount }}</td>
<td></td>
<td>
{!! Form::open(['action'=>['SalaryController#destroy',$employee->id],'class'=>'no-print','method'=>'delete','onsubmit'=>'return deleteConfirm()']) !!}
{!! Form::submit('X',['class'=>'element btnn btn-danger']) !!}
<br/>
<span class="glyphicon glyphicon-edit"></span>
<br/>
<span class="glyphicon glyphicon-usd"></span>
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
Why not just create a CSS class for your anchors and hide them using that class?
foo
foo
And in your CSS:
.only-print{
display:none;
}
#media print{
a.hiddenTab {
display:none;
}
.only-print{
display:block;
}
}
All the anchors you'd want to hide would just use class="hiddenTab".
If you want to hide all a tags which have href set, you can do this:
a[href] { display: none; }

Custom query using DB::select() on laravel 4.2 controller

I had used a custom query in my controller in laravel here is my code in my controller:
public function c_viewSystemUser()
{
$title = "View System Users";
$jSu = DB::select(DB::raw("SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID"));
return View::make('ssims.view_systemUser',compact('title','jSu'));
}
I wanted to display its result in my blade file view_systemUser
here is my code inside the view:
#if ($jSu)
<table class="table table-striped table-hover" id="detailTable">
<thead>
<tr>
<th>System User ID</th>
<th>SystemUser Type ID</th>
<th>System UserName</th>
<th>System User Description</th>
</tr>
</thead>
<tbody>
#foreach ($jSu as $vu)
<tr>
<td>{{ $vu->dbo_systemusers.SystemUserID }}</td>
<td>{{ $vu->dbo_systemtypes.SystemType }}</td>
<td>{{ $vu->dbo_systemusers.SystemUserName}}</td>
<td>{{ $vu->dbo_systemusers.SystemUserDescription}}</td>
</tr>
#endforeach
</tbody>
</table>
And I am having an error:
Undefined property: stdClass::$dbo_systemusers (View:
C:\xampp\htdocs\laravel3\app\views\ssims\view_systemUser.blade.php)
Any suggestions?
Try this:
#foreach ($jSu as $key => $vu)
<tr>
<td>{{ $vu->SystemUserID }}</td>
<td>{{ $vu->SystemType }}</td>
<td>{{ $vu->SystemUserName}}</td>
<td>{{ $vu->SystemUserDescription}}</td>
</tr>
#endforeach
You forgot to join dbo_systemusers with dbo_systemtypes.
Try this code
SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName from dbo_systemusers INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID
And Try this on View page
#foreach ($jSu as $vu)
<tr>
<td>{{ $vu->SystemUserID }}</td>
<td>{{ $vu->SystemType }}</td>
<td>{{ $vu->SystemUserName}}</td>
<td>{{ $vu->SystemUserDescription}}</td>
</tr>
#endforeach

Categories