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>
Related
I am newbie in laravel, i'm trying to show the table like image below
https://i.stack.imgur.com/l52Vo.jpg
#foreach($report_data as $index => $item)
<tbody class="table-content">
<tr>
<td>{{ $index+1 }}</td>
<td style="text-align:left;">{{ $item->customer_fullName }}</td>
<td>{{ $item->customer_phone }}</td>
<td>{{ $item->customer_detail_licensePlate }}</td>
<td>{{ $item->vehicle_brand_name }}</td>
<td>{{ $item->vehicle_model_name }}</td>
</tr>
</tbody>
#endforeach
but the output is like image below
https://i.stack.imgur.com/rSktI.png
Thanks!!
I would do it as so:
In the controller, select the customers eager loading the vehicles.
$customers = Customer::with('vehicles')->get();
return view('customers')->with('customers', $customers);
In the view:
<table>
#foreach($customers as $index => $customer)
<tr>
<td rowspan="$customer->vehicles->count()">
{{ $index+1 }}
</td>
<td rowspan="$customer->vehicles->count()">
{{ $customer->fullName }}
</td>
<td rowspan="$customer->vehicles->count()">
{{ $customer->phone }}
</td>
<td> {{$customer->vehicles[0]->licensePlate }} </td>
<td> {{$customer->vehicles[0]->brandName }} </td>
<td> {{$customer->vehicles[0]->modelName }} </td>
</tr>
#for($i=1;$i<$customer->vehicles->count())
<tr>
<td> {{$customer->vehicles[$i]->licensePlate }} </td>
<td> {{$customer->vehicles[$i]->brandName }} </td>
<td> {{$customer->vehicles[$i]->modelName }} </td>
</tr>
#endfor
#endforeach
</table>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Customer</th>
<th scope="col">Licence Number</th>
<th scope="col">Brand</th>
<th scope="col">Brand Type</th>
</tr>
</thead>
<tbody>
#foreach($report_data as $index => $item)
<tbody class="table-content">
<tr>
<td>{{ $index+1 }}</td>
<td style="text-align:left;">{{ $item->customer_fullName }}</td>
<td>{{ $item->customer_phone }}</td>
<td>{{ $item->customer_detail_licensePlate }}</td>
<td>{{ $item->vehicle_brand_name }}</td>
<td>{{ $item->vehicle_model_name }}</td>
</tr>
</tbody>
#endforeach
</tbody>
use this CDN for Bootstrap style
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
You need not to iterate tbody everytime, just iterate <tr></tr> as below
<table>
<thead>
<tr>
<th>No</th>
<th>Customer</th>
<th>Phone</th>
<th>License Number</th>
<th>Brand</th>
<th>Brand Type</th>
</tr>
</thead>
<tbody class="table-content">
#foreach($report_data as $index => $item)
<tr>
<td>{{ $index+1 }}</td>
<td rowspan="2" style="text-align:left;">{{ $item->customer_fullName }}</td> //rowspan should be in some condition
<td>{{ $item->customer_phone }}</td>
<td>{{ $item->customer_detail_licensePlate }}</td>
<td>{{ $item->vehicle_brand_name }}</td>
<td>{{ $item->vehicle_model_name }}</td>
</tr>
#endforeach
</tbody>
</table>
I use Laravel to show data from Mysql to View by multi-queries.
Here is my Route:
Route::get('/procinstdetail','ProcDetailController#index');
And here is my controller:
use App\act_hi_taskinst;
use View;
class ProcDetailController extends Controller
{
private $act_hi_taskinst;
public function __construct(act_hi_taskinst $act_hi_taskinst) {
$this -> act_hi_taskinst = $act_hi_taskinst;
}
public function index(act_hi_taskinst $act_hi_taskinst, Request $request)
{
$procinstid = $request->get('id');
return View::make('datatrackingdetail')->with('data', $this->act_hi_taskinst->getData($procinstid));
}
}
And my model:
class act_hi_taskinst extends Model
{
public function getData($procinstid) {
$data = array();
$data['taskData'] = DB::select("SELECT NAME_, PRIORITY_, ASSIGNEE_, DUE_DATE_, START_TIME_, END_TIME_, PROC_DEF_ID_ FROM act_hi_taskinst WHERE PROC_INST_ID_ = $procinstid");
$data['varData'] = DB::select("SELECT NAME_, TEXT_ FROM act_hi_varinst WHERE PROC_INST_ID_ = $procinstid");
$data['subprocessData'] = DB::select("SELECT * FROM act_hi_procinst WHERE SUPER_PROCESS_INSTANCE_ID_ = $procinstid");
return $data;
}
}
Final is fetch data to view:
<body>
<h2>Task</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Priority</th>
<th>Assignee</th>
<th>Due Date</th>
<th>Created</th>
<th>Completed</th>
</tr>
#if(isset($data))
#foreach($data as $processTaskDataValue)
<tr>
<td>{{ $processTaskDataValue -> NAME_ }}</td>
<td>{{ $processTaskDataValue -> PRIORITY_ }}</td>
<td>{{ $processTaskDataValue -> ASSIGNEE_ }}</td>
<td>{{ $processTaskDataValue -> DUE_DATE_ }}</td>
<td>{{ $processTaskDataValue -> START_TIME_ }}</td>
<td>{{ $processTaskDataValue -> END_TIME_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Variable</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
#if(isset($data))
#foreach($data as $processVarDataValue)
<tr>
<td>{{ $processVarDataValue -> NAME_ }}</td>
<td>{{ $processVarDataValue -> TEXT_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Sub Process</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>ID_</th>
<th>PROC_INST_ID_</th>
<th>BUSINESS_KEY_</th>
<th>PROC_DEF_ID_</th>
<th>START_TIME_</th>
<th>END_TIME_</th>
<th>DURATION_</th>
<th>START_USER_ID_</th>
<th>START_ACT_ID_</th>
<th>END_ACT_ID_</th>
<th>SUPER_PROCESS_INSTANCE_ID_</th>
<th>DELETE_REASON_</th>
<th>TENANT_ID_</th>
<th>NAME_</th>
</tr>
#if(isset($data))
#foreach($data as $subprocessDataValue)
<tr>
<td> {{$subprocessDataValue -> ID_ }}</td>
<td>{{ $subprocessDataValue -> PROC_INST_ID_ }}</td>
<td>{{ $subprocessDataValue -> BUSINESS_KEY_ }}</td>
<td>{{ $subprocessDataValue -> PROC_DEF_ID_ }}</td>
<td>{{ $subprocessDataValue -> START_TIME_ }}</td>
<td>{{ $subprocessDataValue -> END_TIME_ }}</td>
<td>{{ $subprocessDataValue -> DURATION_ }}</td>
<td>{{ $subprocessDataValue -> START_USER_ID_ }}</td>
<td>{{ $subprocessDataValue -> START_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue -> END_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue -> SUPER_PROCESS_INSTANCE_ID_ }}</td>
<td>{{ $subprocessDataValue -> DELETE_REASON_ }}</td>
<td>{{ $subprocessDataValue -> TENANT_ID_ }}</td>
<td>{{ $subprocessDataValue -> NAME_ }}</td>
</tr>
#endforeach
#endif
</table>
</body>
But I receive error:
Trying to get property 'NAME_' of non-object.
What's wrong with my code?
I'm new with Laravel so I really don't know how to fix it.
In your Model you are creating array with key taskData, varData and subprocessData and you forgot to use this key to your $data array while getting data
<body>
<h2>Task</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Priority</th>
<th>Assignee</th>
<th>Due Date</th>
<th>Created</th>
<th>Completed</th>
</tr>
#if(isset($data))
#foreach($data['taskData'] as $processTaskDataValue)
<tr>
<td>{{ $processTaskDataValue->NAME_ }}</td>
<td>{{ $processTaskDataValue->PRIORITY_ }}</td>
<td>{{ $processTaskDataValue->ASSIGNEE_ }}</td>
<td>{{ $processTaskDataValue->DUE_DATE_ }}</td>
<td>{{ $processTaskDataValue->START_TIME_ }}</td>
<td>{{ $processTaskDataValue->END_TIME_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Variable</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
#if(isset($data))
#foreach($data['varData'] as $processVarDataValue)
<tr>
<td>{{ $processVarDataValue->NAME_ }}</td>
<td>{{ $processVarDataValue->TEXT_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Sub Process</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>ID_</th>
<th>PROC_INST_ID_</th>
<th>BUSINESS_KEY_</th>
<th>PROC_DEF_ID_</th>
<th>START_TIME_</th>
<th>END_TIME_</th>
<th>DURATION_</th>
<th>START_USER_ID_</th>
<th>START_ACT_ID_</th>
<th>END_ACT_ID_</th>
<th>SUPER_PROCESS_INSTANCE_ID_</th>
<th>DELETE_REASON_</th>
<th>TENANT_ID_</th>
<th>NAME_</th>
</tr>
#if(isset($data))
#foreach($data['subprocessData'] as $subprocessDataValue)
<tr>
<td><a href= "{{ url('/procinstdetail') }}?id={{
$subprocessDataValue -> ID_ }}&endtime={{ $subprocessDataValue ->
END_TIME_ }}"> {{$subprocessDataValue -> ID_ }}</a></td>
<td>{{ $subprocessDataValue->PROC_INST_ID_ }}</td>
<td>{{ $subprocessDataValue->BUSINESS_KEY_ }}</td>
<td>{{ $subprocessDataValue->PROC_DEF_ID_ }}</td>
<td>{{ $subprocessDataValue->START_TIME_ }}</td>
<td>{{ $subprocessDataValue->END_TIME_ }}</td>
<td>{{ $subprocessDataValue->DURATION_ }}</td>
<td>{{ $subprocessDataValue->START_USER_ID_ }}</td>
<td>{{ $subprocessDataValue->START_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue->END_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue->SUPER_PROCESS_INSTANCE_ID_ }}</td>
<td>{{ $subprocessDataValue->DELETE_REASON_ }}</td>
<td>{{ $subprocessDataValue->TENANT_ID_ }}</td>
<td>{{ $subprocessDataValue->NAME_ }}</td>
</tr>
#endforeach
#endif
</table>
</body>
DB::select() will return an Array. So call it's property accordingly.
small POC
Update: Also as per other answer, you are not iterating over elements of $data, not actual data that you get from DB::select.
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
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
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; }