I was able to fetch certain data before but when I tried to add more code for pagination. It doesnt work anymore.
I need to paginate the data from API
error: "Trying to get property 'name' of non-object."
This is the result if I
if I dd($response) the results are:
{#274 ▼
+"pagelen": 10
+"next": "https://bitbucket.org/!api/2.0/repositories/spycetek?page=2"
+"values": array:10 [▶]
+"page": 1
+"size": 59
}
// I should paginate this. Here is my code for the controller.
public function index(Request $request, $page = 1)
{
$request = $this->client->get("https://bitbucket.org/!api/2.0/repositories/{$this->username}?page=" . $page,
[
'headers' => ['Authorization' => 'Bearer ' . $this->token]
]);
$response = json_decode($request->getBody()->getContents());
$repositories = $response->values;
$pagination = $response->pagelen;
$has_next_page = $pagination['has_next_page'];
$current_page = $pagination['page'];
$has_previous_page = $pagination['previous'];
$next_page = $pagination['next'];
return view('bitbuckets.repository')->with(compact('repositories'),
[ 'has_next_page' => $has_next_page,
'current_page' => $current_page, 'has_previous_page' => $has_previous_page,
'next_page' => $next_page]);
}
**//this is my blade.php file**
#extends('layoutss.layout')
#section('content')
<div class="container">
<div class="row" id="load" style="position: relative;">
<table class="table table-hover">
<thead>
<tr>
<th scope="col" class="text-secondary">Repositories</th>
</tr>
</thead>
<tbody>
#foreach($repositories as $key => $repository)
<tr>
<td>
{{$repository->name }}
</td>
</tr>
#if(isset($current_page))
<?php
$prev = $current_page - 1;
?>
#if(($has_next_page == true) && ($has_previous_page == false))
<li>Next</li>
#elseif(($has_next_page == false) && ($has_previous_page == true))
<li>Previous</li>
#elseif(($has_next_page == true) && ($has_previous_page == true))
<li>Previous</li>
<li>Next</li>
#endif
#endif
{{$repositories->links()}}
#endforeach
</tbody>
</table>
</div>
</div>
#endsection
and this is my code for routes.
Route::get('/{page?}', 'bb#index');
what is wrong with my codes
I messed up when it comes to pagination.
in blade.php was trying to display the list of all repositories and I wanted to paginate them. But I couldn't because of the error.
Related
In my blade view, it is giving me an error Call to undefined method App\Student:: contains()
my controller
if($auth->user()->getRoleNames() == '["Parent"]'){
$id = $auth->user()->Parents_id;
$parent = ParentName::find($id);
$student = $parent->students;
$announce = AnnounceMent::get();
$roletype='parent';
return view('announcement.index',compact('student','roletype','announce'));
}
my view file
#foreach($announce as $ann)
#if($student->contains('id', $ann->student_id))
<tr>
<td>{{$i}}</td>
<td>{{$ann->announcement_type}}</td>
<td>
<?php $course = \App\Course::find($ann->course_id) ?>
{{$course->course_name}}
</td>
<td>
<?php $student = \App\Student::find($ann->student_id) ?>
{{$student['firstname'].' '.$student['lastname']}}
</td>
<td>{{$ann->description}}</td>
<td>
<a class="btn btn-success" href='{{ url("viewannounce/{$ann->id}") }}'>View</a>
</td>
</tr>
#endif
#php($i++)
#endforeach
this is my collection I am getting dd($students)
Collection {#595 ▼
#items: array:3 [▼
0 => Student {#596 }
1 => Student {#597 }
2 => Student {#598 }
]
}
contains is a collection method, you are calling it with a non-collection, if it will be App\Student::all()->contains('something') it will work fine, but App\Student::find(1)->contains('something') or App\Student::contains('something') will not work
Tinker results
>>> App\User::find(1)->contains('email')
BadMethodCallException with message 'Call to undefined method App/User::contains()'
>>> App\User::all()->contains('email')
=> false
>>> App\User::contains('email')
BadMethodCallException with message 'Call to undefined method App/User::contains()'
>>>
You can do
$student->id == $ann->student_id
in your situation, I guess.
I'm trying to render a list from my JsonResult Controller. It's ok, I receive data in my Angular service, but a in trouble to render it in a list using ng-repeat. It´s renders a big empty list.
When the data is not a list, it´s works.
Angular.
Debug
var app = angular.module('FileApp', []);
app.service('ngFileService', function ($http) {
this.getFileByFileCode = function (fileCodigo) {
var response = $http.get("/Files/GetFile?fileCodigo=" + fileCodigo);
return response;
};
});
app.controller('ngFileController', function ($scope, ngFileService) {
$scope.filterFileCode = "";
$scope.getFilteredFile = function () {
var promise = ngFileService.getFileByFileCode($scope.filterFileCode);
promise.then(function (resp) {
$scope.File = resp.data;
$scope.Message = "Call is Completed Successfully";
}, function (err) {
$scope.Message = "Call Failed " + err.status;
});
};
});
HTML
<tr>
<td>Enter Search Value:</td>
<td><input type="text" ng-model="filterFileCode" class="form-
control" ng-change="getFilteredFile()" /></td>
</tr>
<table class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Documentos Gerais File</th>
<th></th>
<th>CTB</th>
<th>COM</th>
<th>Site</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="f in File">
<td>Documentos</td>
<td>{{f.FileCTB}}</td>
<td>{{f.FileCOM}}</td>
<td>{{f.FileSite}}</td>
</tr>
</tbody>
</table>
Erro
I expect to render a list of boolens values.
**DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]**
[SOLVED]
I find de solution making the above solution:
<tbody>
<tr>
<td>Documentos</td>
<td>Comandos</td>
<td><span ng-repeat="(key, value) in File.FileCTB track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileCOM track by $index">
{{value}}</span></td>
<td><span ng-repeat="(key, value) in File.FileSite track by $index">
{{value}}</span></td>
</tr>
</tbody>
I solved this problem storing in a viewModel object all date below:
DataCriacao: "/Date(-62135596800000)/"
DataFim: "06/07/2018"
DataInicio: "26/06/2018"
DescricaoServico: null
FileCOM: (2) [true, false]
FileCTB: (2) [false, false]
FileCodigo: 190562
FileCodigoId: 0
FileCodigoNv: null
FileMimeType: null
FileSite: (2) [false, false]
So, I can iterate only in the attribute that is collections ou array.
I have a table AssetsAssignations, with hundreds of rows. In some cases, the user needs to select many rows with a checkbox, and change the "status" for all of them together.
In my controller, I have this function
public function editMultiple()
{
$assetStatuses = $this->AssetsAssignations->AssetStatuses->find('list');
$this->paginate = [
'contain' => ['Assets', 'AssetStatuses', 'Clients', 'Rooms'],
'sortWhitelist' => [
'Assets.model_number',
'Assets.serial_number',
'AssetStatuses.name',
'Clients.last_name',
'Rooms.name',
]
];
$assetsAssignations = $this->request->data;
$assetsAssignations_ids = array();
foreach($assetsAssignations as $a){
$assetsAssignations_ids[$a['id']] = $a['id'];
$this->AssetsAssignations->updateAll(
array('AssetAssignation.id' => $assetsAssignations_ids)
);
$this->Session->setFlash(__('Statsus is updated for the selcted entries!'));
}
debug($assetsAssignations);
$query = $this->AssetsAssignations->find()
->contain(['Assets', 'AssetStatuses', 'Clients', 'Rooms']);
$filter = $this->Filter->prg($query);
$assetsAssignations = $this->paginate($filter, ['maxLimit' => 10000, 'limit' => 10000]);
$this->set(compact('assetsAssignations', 'assetStatuses'));
$this->set('_serialize', ['assetsAssignations']);
}
In my edit_multiple.ctp, I use a javascript to filter the data. And I put this code:
<table class="hoverTable dataTable">
<thead>
<tr>
<th>Select</th><th>Model Number</th><th>Serial Number</th><th>Room</th><th>Client</th><th>Status</th>
</tr>
</thead>
</thead>
<?php foreach ($assetsAssignations as $assetsAssignation): ?>
<tr>
<td><input name="data[AssetsAssignations][id][]" value="<?= $assetsAssignation->id ?>" id="AssetsAssignationsId1" type="checkbox"></td>
<td><?= $assetsAssignation->has('asset') ? $assetsAssignation->asset->model_number : '' ?></td>
<td><?= $assetsAssignation->has('asset') ? $assetsAssignation->asset->serial_number : '' ?></td>
<td><?= $assetsAssignation->has('room') ? $assetsAssignation->room->name : '' ?></td>
<td><?= $assetsAssignation->has('client') ? $assetsAssignation->client->last_name . ', ' . $assetsAssignation->client->first_name: '' ?></td>
<td><?= $assetsAssignation->has('asset_status') ? $assetsAssignation->asset_status->name : '' ?></td>
</tr>
<?php endforeach; ?>
</table>
<legend><?= __('') ?></legend>
</div>
<?= $this->Form->create($assetsAssignation) ?>
<fieldset>
<div class="row">
<div class="col-xs-3"><?= $this->Form->input('asset_status_id', ['options' => $assetStatuses, 'empty' => true, 'label' => __('Change Status To')]) ?></div>
</div>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
When I debug the result, checking 3 entries, I get this:
[
'data' => [
'AssetsAssignations' => [
'id' => [
(int) 0 => '411',
(int) 1 => '413',
(int) 2 => '415'
]
]
],
'asset_status_id' => '3'
]
My question is: How to pass the selected row IDs to the "Submit" button after selecting the checkboxes ?
Thanks in advance.
I think that what you want to do is something like
if($this->request->is('post')
{
$ids = $this->request->data('data.AssetsAssignations.id');
$asset_status_id = $this->request->data('asset_status_id');
$this->AssetsAssignations->updateAll(
['asset_status_id ' => $asset_status_id ]
['id IN' => $ids]
);
}
Based on what #Arilia suggested, tis worked for me. In my controller, function, I put this:
$this->request->data;
$data = $this->request->data;
debug($data);
if($this->request->is(['patch', 'post', 'put']))
{
$ids = $this->request->data('data.AssetsAssignations.id');
$asset_status_id = $this->request->data('asset_status_id');
$this->AssetsAssignations->updateAll(
['asset_status_id ' => $asset_status_id ],
['id IN' => $ids]
);
}
In my view, I put this:
<td><input type="checkbox" name="data[AssetsAssignations][id][]" value="<?= $assetsAssignation->id ?>" id="ApplicationId1" ></td>
Database Table Structure
Data need to show
Please note: The city_from and city_to not fixed. It comes from city table. But single_or_group_id is fixed 1 = Single and 2 = Group.
Should try this. Think it will work according to your condition
select a.Trans_rent as Single, b.Trans_rent as Group
from table as a
inner join table as b on a.city_from = b.city_from and a.city_to = b.city_to
and b.single_or_group_id = 2
where a.single_or_group_id = 1
You can see this. Hope it will help you.
<?php
$map_city = ['2'=>'Madina','3'=>'Makkah'];
$single_group = ['1'=>'Single','2'=>'Group'];
$data = [
[
'city_form' => 2,
'city_to' => 3,
'single_or_group_id' => 1,
'rent' => 1000
],
[
'city_form' => 2,
'city_to' => 3,
'single_or_group_id' => 2,
'rent' => 4000
],
];
?>
<table style="width:25%" border=1>
<?php $is_first = true; ?>
<?php foreach($data as $single){ ?>
<?php if($is_first) { ?>
<tr>
<th colspan=2><?php echo $map_city[$single['city_form']] .'-'. $map_city[$single['city_to']];?></th>
</tr>
<tr>
<?php foreach($data as $single){ ?>
<td><?php echo $single_group[$single['single_or_group_id']];?></td>
<?php } ?>
</tr>
<tr>
<?php foreach($data as $single){ ?>
<td><?php echo 'S.R '.$single['rent'];?></td>
<?php } ?>
</tr>
<?php $is_first = false; } ?>
<?php } ?>
</table>
Hello i'm working in Angular 5 and my api delete works (postman & site --> link = api/employees/:id --> localhost:4200/api/employees/5a2025db26589c230865527a) , but I think my HTML code is wrong or the steps in between. Can somebody help me plz i've been stuck at this all day..
HTML :
<h2>Info employees</h2>
<table class="table">
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
<th>Wage</th>
</tr>
<tr *ngFor="let employee of employees">
<td>{{ employee.name }}</td>
<td>{{ employee.age }}</td>
<td> {{ employee.email }} </td>
<td> {{ employee.wage}}</td>
<td>{{employee._id}}</td>
<td>
Delete
</td>
</tr>
</table>
Component.ts :
deleteEmployee(id){
var employees = this.employees;
this._dataService.deleteEmployee(id)
.subscribe(data => {
if(data.n == 1){
for(var i = 0;i < employees.length;i++){
if(employees[i]._id == id){
employees.splice(i, 1);
}
}
}
});
}
data.service :
deleteEmployee(id){
return this._http.delete('/api/employees/'+id)
.map(res => res.json());
}
replace data-ng-click with (click) and make the HTML element a <button> since it's not redirecting anywhere.
Edit: employees.splice(i, 1); replace with this.employees.splice(i, 1); to reflect the change in the view.
Actually, you need to change the logic of
if(data.n == 1){
for(var i = 0;i < employees.length;i++){
if(employees[i]._id == id){
employees.splice(i, 1);
}
}
}
Because basically you are deleting user in the view without considering the data of the backend service. What response do you get from that DELETE endpoint ? Does it return the deleted user or the id of the deleted user ?
maybe little late ..but that if you try something like this .. with .filter() ES6 (also Typescript) Array native method ..
so like:
eleteEmployee(id){
var employees = this.employees; //why use it?? ..no need it
this._dataService.deleteEmployee(id)
.subscribe(data => {
if(data.n == 1){
this.employees = this.employees.filter(xx=> xx._id != id) // <--- so filter and RETURN ALL non matching given ID
}
});
}
Hope it helps you !! ...