I'm using laravel-5.4 in this project
with "maatwebsite/excel"
I'm planning to create a feature for my website where the I can upload an excel file then show the data of this file in my view
the form I used to upload and send my data to the back end
public function bundleaddstudent(Request $request)
{
if($request->hasFile('excelstudent')){
$File = $request->file('excelstudent');
$path = $File->getRealPath();
$data = Excel::load($path, function($reader) {
})->toObject();
return view('User.content.tobe_added_students')
->with('selection', $this->selection())
->with('Students', $data);
}
else
{
return view('User.content.Add_student')
->with('selection', $this->selection())
->with('Students', 'No Data')
->with('request', $request);
}
}
now that the file that has been uploaded and has been handled in my controller for it to be converted as data object and was also been passed with the new view.
I now need to handle the passed data in my view this is how I've done it
#isset($Students)
#foreach ($Students as $key => $value)
<tr>
<td> {{$value}}</td>
</tr>
#endforeach
#endisset
but sadly the output of this is like this
if I try to {{ $value->dump() }}
an error would occur saying Method dump does not exist.
if I try to {{ $key }}
the output is an integer starting for 0 - 4 outputting it like
----------------------------
| studentID | Firstname |
----------------------------
| 1 | |
| 2 | |
| 3 | |
| 4 | |
you get the Idea
I also tried {{ $value->studentId }} but it is showing me nothing
base on the Comment of #LrdArc that I should Try
#isset( $Students )
{{ dd( $Students ) }}
#endisset
OUTPUT:
LaravelExcelReader {#353 ▼
+excel: PHPExcel {#361 ▶}
+reader: PHPExcel_Reader_Excel2007 {#354 ▶}
+file: "/tmp/phpu3zVBH"
+columns: []
+title: "phpu3zVBH"
+ext: ""
+encoding: false
+format: "Excel2007"
+parsed: RowCollection {#430 ▼
#title: "Sheet1"
#items: array:5 [▼
0 => CellCollection {#495 ▼
#title: null
#items: array:9 [▼
"studentid" => "15-2000332"
"firstname" => "Dummy1"
"lastname" => "Dummy1"
"middlename" => "Dummy1"
"course" => "Dummy1"
"ay" => "Dummy1"
"gender" => "Dummy1"
"address" => "Dummy1"
"contact" => "Dummy1"
]
}
1 => CellCollection {#496 ▼
#title: null
#items: array:9 [▼
"studentid" => "15-2000333"
"firstname" => "Dummy2"
"lastname" => "Dummy2"
"middlename" => "Dummy2"
"course" => "Dummy2"
"ay" => "Dummy2"
"gender" => "Dummy2"
"address" => "Dummy2"
"contact" => "Dummy2"
]
}
2 => CellCollection {#515 ▶}
3 => CellCollection {#514 ▶}
4 => CellCollection {#513 ▶}
]
}
Edit:
okay I've just tested it. Change toObject() into get() in your controller.
It's an object. Try something like this in your view:
#isset( $Students )
#foreach ( $Students as $student )
<tr>
<td>{{ $student->studentID }}</td>
<td>{{ $student->firstname }}</td>
<td>{{ $student->lastname }}</td>
<td>{{ $student->middlename }}</td>
</tr>
#endforeach
#endisset
Related
I'm trying to create a custom-field that is an entity-single-select for customers, exactly like the one in the sw-order module as seen here
sw-order-create-details-header > sw-entity-single-select
Is there some way for me, to configure the look of my custom-field to be the same as the extended select-field in the sw-order module?
With that i mean, inclusive of firstName, lastName, address and customernumber?
(Without creating a a new component)
What i have so far is this:
protected $customFields = [
[
'name' => 'referrer_set',
'config' => [
'label' => [
'en-GB' => 'Referrer',
'de-DE' => 'Referrer',
],
],
'customFields' => [
[
'active' => true,
'name' => 'refferer_set',
'type' => CustomFieldTypes::ENTITY,
'config' => [
'componentName' => 'sw-entity-single-select',
'entity' => CustomerDefinition::ENTITY_NAME,
'placeholder' => "Wurde empfohlen von ...",
'highlightSearchTerm' => true,
'allowEntityCreation' => false,
'show-clearable-button' => true,
'labelProperty' => 'firstName',
'label' => [
'en-GB' => 'Empfohlen von',
'de-DE' => 'Empfohlen von',
],
],
],
],
'relations' => [
[
'entityName' => CustomerDefinition::ENTITY_NAME,
],
],
],
];
Unfortunately this isn't quite so trivial to achieve.
You could override the component which is responsible for rendering custom fields sw-form-field-renderer.
Inside the override you check if it is your specific custom field that should be rendered. In the template of the override you then set the content of the slot result-item, which is a corresponding to each option in the dropdown. You'll additionally have to extend the binds of the component with a criteria to add the billing address of the customer as an association.
The override:
import template from './sw-form-field-renderer.html.twig';
const { Component } = Shopware;
const { Criteria } = Shopware.Data;
Component.override('sw-form-field-renderer', {
template,
computed: {
isMyCustomField() {
return this.config.componentName === 'sw-entity-single-select' && this.$attrs.name === 'refferer_set';
},
bind() {
const bind = this.$super('bind');
if (this.isMyCustomField) {
const criteria = new Criteria;
criteria.addAssociation('defaultBillingAddress.country');
bind.criteria = criteria;
}
return bind;
},
},
});
The template sw-form-field-renderer.html.twig:
{% block sw_form_field_renderer_scope_slots %}
{% parent %}
<template
v-if="isMyCustomField"
#result-item="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
>
<!-- copy/paste from sw-order-create-details-header -->
<li
is="sw-select-result"
:selected="isSelected(item)"
v-bind="{ item, index }"
class="sw-order-create-details-header__customer-result"
#item-select="setValue"
>
<div class="sw-order-create-details-header__customer-result-item has-many-childrens">
<div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'firstName') || getKey(item, `translated.firstName`)"
:search-term="searchTerm"
/>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'lastName') || getKey(item, `translated.lastName`)"
:search-term="searchTerm"
/>
</div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'customerNumber') || getKey(item, `translated.customerNumber`)"
:search-term="searchTerm"
class="text-truncate"
/>
</div>
<div
v-if="getKey(item, 'company') || getKey(item, `translated.company`)"
class="sw-order-create-details-header__customer-result-item"
>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'company') || getKey(item, `translated.company`)"
:search-term="searchTerm"
/>
</div>
<div class="sw-order-create-details-header__customer-result-item text-gray-500">
{{ item.defaultBillingAddress.street }} <br>
{{ item.defaultBillingAddress.zipcode }} {{ item.defaultBillingAddress.city }} <br>
{{ item.defaultBillingAddress.country.name }}
</div>
</li>
</template>
{% endblock %}
I've got a problem with display of this function:
{% for row in topics %}
<tr align="center">
<td class="td"><img src="{{ asset('images/tdlogo.jpg') }}" alt="Logo"></td>
<td align="left" class="td"><a href="{{ url('topic_view', {'slug': row.idForumSection, 'id': row.idForumTopic}) }}"
title="{{ row.nameTopic }}">{{ row.nameTopic }}</td>
{% for row in posts %}
<td class="td">{{ row.post }}</td>
{% endfor %}
</tr>
{% endfor %}
There is a for which creates table showing forum topics, and a second for inside which is supposed to display post count for each topic. However, as it is two fors inside each other, second one iterates fully before next topic is displayed. As an affect, every topic shows all counts of topic posts from each topic.
Meanwhile, first topic should have posts:4, and second posts:1.
I tried to do something like this:
<td class="td">{{ posts.0.post }}</td>
And it works, but show first topic number of posts for all of topics.
Replacing "0" with a variable which would increase with each iteration of first "for" would work (so starting with 0, then 1, then 2, displaying numbers of posts for each topic), but i cannot make variable work inside this function.
Here is a dump of functions calling to database for variables (there are two functions, one for topics and second one for posts).
array(2) { [0]=> array(3) { ["nameTopic"]=> string(9) "Regulamin" ["idForumSection"]=> string(1) "1" ["idForumTopic"]=> string(1) "1" } [1]=> array(3) { ["nameTopic"]=> string(13) "Administracja" ["idForumSection"]=> string(1) "1" ["idForumTopic"]=> string(1) "5" } }
topics:
array(2) { [0]=> array(3) { ["nameTopic"]=> string(9) "Regulamin" ["idForumSection"]=> string(1) "1" ["idForumTopic"]=> string(1) "1" } [1]=> array(3) { ["nameTopic"]=> string(13) "Administracja" ["idForumSection"]=> string(1) "1" ["idForumTopic"]=> string(1) "5" } }
posts:
array(2) { [0]=> array(3) { ["idForumTopic"]=> string(1) "1" ["idForumSection"]=> string(1) "1" ["post"]=> string(1) "4" } [1]=> array(3) { ["idForumTopic"]=> string(1) "5" ["idForumSection"]=> string(1) "1" ["post"]=> string(1) "1" } }
Please, help me!
i have user object that contain all user fields.
and listFields array that have ["user.id", "user.email","user.gender"].
so variables in string.
i want to loop listFields and print it's original value from user object
currently user.id user.email print on screen.
i want to print it's value in screen.
have any solution for this! or it is possible?
Mycode
{% for fieldName in listFields %}
<td>
{{ fieldName }}
</td>
{% endfor %}
If you want to print dynamic variables u can make use of the function attribute:
{% set user_fields = [ 'user.id', 'user.email', 'user.gender', 'alice.email', 'bob.id', 'bob.foo', ] %}
{% for field in user_fields %}
{{ attribute(attribute(_context, (field|split('.'))[0])|default([]), (field|split('.'))[1])|default(null) }}
{% endfor %}
demo
array:3 [▼
"user" => array:3 [▼
"id" => 42
"email" => "user#example.com"
"gender" => 0
]
"bob" => array:3 [▼
"id" => 1
"email" => "bob#example.com"
"gender" => 0
]
"alice" => array:3 [▼
"id" => 100
"email" => "alice#example.com"
"gender" => 1
]
]
I am making a nodejs app which can fetch flights from the KIWI api, it returns a json list, and since you parameters like from and to, it should return a list of flights.
I can successfully get that, but when I want to display everything I dont know how to do it.
This is my render:
render(){
return (
<table className="table table-hover">
<thead>
<tr>
<th>Flight #</th>
<th>From</th>
<th>To</th>
</tr>
</thead>
<tbody>
{this.props.flights.map(this.renderFlights)}
</tbody>
</table>
);
}
and
renderFlights(flightData){
// add key to make them unique
return(
<tr>
<td>{flightData.data[0].id}</td>
<td>{flightData.data[0].mapIdfrom}</td>
<td>{flightData.data[0].mapIdto}</td>
</tr>
);
}
{this.props.flights.map(this.renderFlights)} just maps the first one in the array, I know that I have to use foreach, but I dont know how I can use this to print everything in the list, flight id plus the from and to, so when u fetch the flights u get around 15, and I want to be able to display all the 15 flights can someone help me out here?
this returns undefined for forEach:
<tbody>
{
this.props.flights.array.forEach(element => {
this.renderFlights
})
}
</tbody>
I found your API and test interface here: https://skypickerbookingapi1.docs.apiary.io/#reference/check-flights/checkflights/check_flights?console=1
So it seems that you are getting this object for your response:
{
"server_time": 1516568910,
"flights_checked": false,
"extra_fee": 0,
// blah blah,
"flights": [
// first flight
{
"bags_recheck_required": false,
"dtime_unix": 1524646800,
"extra": "",
"atime_unix": 1524651600,
"priority_boarding": {
"currency": null,
"price": null,
"is_possible": false
},
"price": 313,
"currency": "NOK",
"price_new": 313,
// blah blah
},
// second flight
{
"bags_recheck_required": true,
"dtime_unix": 1524683400,
"extra": "",
"atime_unix": 1524691800,
"priority_boarding": {
"currency": null,
"price": null,
"is_possible": false
},
"price": 1560,
"currency": "NOK",
"price_new": 1560,
// blah blah
},
// more and more flights
So I'm guessing that your "this.props.flights" is referring to the "flights" property of the above object.
Now, you need to use "map", not "foreach":
this.props.flights.map(this.renderFlights) //this is correct
And your callback function should be:
renderFlights(one_single_flight){
// add key to make them unique
return(
<tr>
<td>{one_single_flight.id}</td>
<td>{one_single_flight.src_country}</td>
<td>{one_single_flight.dst_country}</td>
</tr>
);
}
}
This is how I was able to get the result I wanted:
renderFlights(flightData){
const result = flightData._results;
var rows = [];
for (var i = 0; i < result; i++) {
rows.push(
<tr key={i} >
<td>{flightData.data[i].mapIdfrom}</td>,
<td>{flightData.data[i].mapIdto}</td>,
</tr>
);
}
return <tbody>{rows}</tbody>;
}
This prints all the available flights for some certain date.
I'm picking information from the database in to a dropdown
and here it
-------------------
id | username
-------------------
10 | llj
12 | AFS
How can I obtain this:
<option value="10">llj</option>
<option value="12">AFS</option>
in symfony2
->add('supervisor','entity', array(
'class' => 'AdminBundle:supervisor',
'expanded' => false,
'multiple' => false,
'placeholder'=>'',
'empty_value' => null
))