How to use Laravael 5.2 custom pagination? - pagination

I am trying to make a custom pagination, feeded with data from an array. I use an array/object and not result from query, becouse I can't get the data only from the query,the data is calculated with other funtions and inserted in array.
This is how array looks like(can also be an object):
0 => array:7 [▼
"name" => "Arnold"
"group_id" => "1004"
"trans_number" => "38"
"totalCommissions" => "669.25"
"paidTransactions" => 675
"reversedTransactions" => 362
]
1 => array:7 [▼
"name" => "Nixon"
"group_id" => "1038"
"trans_number" => "787"
"totalCommissions" => "925.25"
"paidTransactions" => 1340
"reversedTransactions" => 906
]
2 => array:7 [▼
"name" => "Rhoe, Brittany"
"group_id" => "1049"
"trans_number" => "720"
"totalCommissions" => "963.75"
"paidTransactions" => 1695
"reversedTransactions" => 1147
]
3 => array:7 [▼
"name" => "Perez"
"group_id" => "1026"
"trans_number" => "1147"
"totalCommissions" => "1,459.75"
"paidTransactions" => 2398
"reversedTransactions" => 1527
]
The idea is: how to use Laravel 5.2 Pagination class, to render that data in blade view? most of the examples on web looks to be abit outdated....or I can't figure out how to make it.

You can find the documentation for the Paginator here:
Paginator Doc
LengthAwarePaginator Doc
A simple example, using Paginator:
in controller:
$paginator = new \Illuminate\Pagination\Paginator($array, $perPage, $currPage);
in view:
<div class="container">
#foreach ($paginator as $person)
{{ $person->name }}
{{ $person->group_id }}
{{ $person->trans_number }}
{{ $person->totalCommissions }}
{{ $person->paidTransactions }}
{{ $person->reversedTransactions }}
#endforeach
</div>
// render pagination buttons
{!! $paginator->links() !!}

Related

Logstash Plug-in Development

I am trying to develop a new logstash plugin in my development Elasticsearch stack environment.
I started with generating the skeleton for my new plug-in using the logstash-plugin generate utility. Once I had this in place I then was able to build my plug-in using the gem build utility which ran without error and created a gem for me. I then ran the logstash-plugin install utility which successfully installed my plug-in.
The entry in my logstash.gem looks like this--
gem "logstash-output-s3-4.3.3", "0.1.0", :path => "./vendor/bundle/jruby/2.5.0/gems/logstash-output-s3-4.3.3"
I then took the code from the actual logstash plug-in that I'm hoping to modify and copied it into my new plug-in directory and then created a new logstash.conf file to test with using my new plug-in and started the logstash service. It ran as expected moving data from the servers that were being watched in the appropriate s3 buckets.
logstash.conf output section--
output {
s3{
region => "us-east-1"
bucket => "xxxx"
prefix => "Dev/xxxx/%{+YYYY}/%{+MM}/%{+dd}/"
server_side_encryption => true
server_side_encryption_algorithm => "aws:kms"
ssekms_key_id => "xxxx"
validate_credentials_on_root_bucket => false
codec => "json_lines"
size_file => 1024000
time_file => 5
rotation_strategy => "size_and_time"
temporary_directory => "../../LogstashS3OutputData/temp/"
canned_acl => "private"
}
s3{
region => "us-east-1"
bucket => "xxxx"
prefix => "Dev/xxxx/%{+YYYY}/%{+MM}/%{+dd}/"
server_side_encryption => true
server_side_encryption_algorithm => "aws:kms"
ssekms_key_id => "xxxx"
validate_credentials_on_root_bucket => false
codec => "json_lines"
size_file => 1024000
time_file => 5
rotation_strategy => "size_and_time"
temporary_directory => "../../LogstashS3OutputData/temp/"
canned_acl => "private"
}
}
My next step was and this is where I am having issues was to try and create a new property for the plug-in called file_prefix--
s3{
region => "us-east-1"
bucket => "xxxx"
prefix => "Dev/xxxx/xxxx/%{+YYYY}/%{+MM}/%{+dd}/"
file_prefix => "test"
server_side_encryption => true
server_side_encryption_algorithm => "aws:kms"
ssekms_key_id => "arn:aws:kms:xxxx"
validate_credentials_on_root_bucket => false
codec => "json_lines"
size_file => 1024000
time_file => 5
rotation_strategy => "size_and_time"
temporary_directory => "../../LogstashS3OutputData/temp/"
canned_acl => "private"
}
I modified the following files in my solution
\vendor\bundle\jruby\2.5.0\gems\logstash-output-s3-4.3.3\spec\outputs\s3_spec.rb
added "file_prefix" => file_prefix at line 15
\vendor\bundle\jruby\2.5.0\gems\logstash-output-s3-4.3.3\spec\supports\helpers.rb
added let(:file_prefix) {} at line line 12
added "file_prefix" => file_prefix, at line 19
\vendor\bundle\jruby\2.5.0\gems\logstash-output-s3-4.3.3\lib\logstash\outputs\s3.rb
added config :file_prefix, :validate => :string right after the statement config :prefix, :validate => :string, :default => '' at line 154
added #file_prefix = file_prefix at line 226
Now when I start the logstash service I get this error message
Unknown setting 'file_prefix' for s3
I've searched and I've tried everything I can think but I can't get past this hurdle.
TIA,
Bill Youngman
This can be considered closed as I am using a similar feature request in the s3 output plugin developer branch as a starting point for my project.
Thanks,
-Bill

Include tag in TWIG not work,Run is blank

I don't know it not work.Server environment:
Twig:3.0
PHP:7.X
nginx:1.15.11
{{ include 'Include/header.html' }}
Templates file:
|-index.html
|-content.html
|-Include
|- head.html
|- footer.html
index.php:
$loader = new Twig_Loader_Filesystem(ROOT_PATH.'/Templates');
$twig = new Twig_Environment($loader, [
'cache' => ROOT_PATH.'/Cache',
'auto_reload' => true,
'debug' => true
]);
echo $twig->render('index.html');
index.html:
{{ include 'Include/head.html' }}
<article>
body
<article>
{{ include 'Include/footer.html' }}
it doesn't work,Page is blank.
First, try comment out if in dev
'cache' => ROOT_PATH.'/Cache',
then got typo error
{{ include 'Include/foother.html' }}
to
{{ include 'Include/footer.html' }}
I suggest you try do not include any sub twig first and render simple 1 twig first. If success then just include and try again.

Showing category thumbnails in opencart 3 menu

I'm looking for a way to show the category thumbnail in the menu. Is this possible?
Specifically for OpenCart 3.
OpenCart 3.0.2.0, Default theme
Open this file:
catalog\controller\common\menu.php
Find:
$this->load->model('catalog/product');
Add after it:
$this->load->model('tool/image');
Find:
$data['categories'][] = array(
Replace with:
if($category['image']){
$image = $this->model_tool_image->resize($category['image'], 30, 30);
} else {
$image = false;
}
$data['categories'][] = array(
'image' => $image,
Then open this file:
catalog\view\theme\default\template\common\menu.twig
Find:
{{ category.name }}
There are three occurrence, add before first and last one:
<img src="{{ category.image }}" alt="{{ category.name }}"/>{% endif %}
Here is the result:
for submenu use:
$children_data[] = array(
'image' => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : false,
or
'image' => $child['image'] ? $this->model_tool_image->resize($child['image'], 20, 20) : $this->model_tool_image->resize('your-default-image.jpg', 20, 20),
in template
{% for child in children %}
<li>{% if child.image %}<img src="{{ child.image }}" alt="{{ child.name }}" />{% endif %}{{ child.name }}</li>
{% endfor %}
If missed something, follow here

Logstash - Data from Kafka to ES

Using logstash 5.0.0, Taking kafka source as the input -> taking the data and producing the output in Elasticsearch. (ElasticSearch version 5.0.0)
Logstash conf:
input{
kafka{
bootstrap_servers => "XXX.XXX.XX.XXX:9092","XXX.XXX.XX.XXX:9092","XXX.XXX.XX.XXX:9092"
topics => ["a-data","f-data","n-data"]
group_id => "sound"
auto_offset_reset => "earliest"
consumer_threads => 2
}
}
filter{
json{
source => "message"
}
}
output {
elasticsearch {
hosts => [ "XXX.XXX.XX.XXX:9200" ]
}
}
When I run the below configuration , i am getting this following error.
$ ./logstash -f sound.conf
Sending Logstash logs to /logstash-5.0.0/logs which is now configured vi a log4j2.properties.
[2017-01-17T10:53:29,273][ERROR][logstash.agent ] fetched an invalid c onfig {:config=>"input{\nkafka{\nbootstrap_servers => \"XX.XXX.XXX.XX:9092\",\"XXX.XXX.XX.XXX:9092\",\"XXX.XXX.XX.XXX:9092\"\ntopics => [\"a-data\",\"f-data\ ",\"n-data\"]\ngroup_id => \"sound\"\nauto_offset_reset => \"earliest\"\nc onsumer_threads => 2\n}\n}\nfilter{\njson{\nsource => \"message\"\n}\n}\noutput {\nelasticsearch {\nhosts => [ \"XX.XX.XXX.XX:9200\" ]\n}\n}\n\n", :reason=>"Ex pected one of #, {, } at line 3, column 40 (byte 54) after input{\nkafka{\nboots trap_servers => \"XX.XX.XXX.XX:9092\""}
Can anyone help me with this configuration.
Shouldn't your topic be topics which is an array, where you've inserted the values as a hash:
topics => ["a-data","f-data","n-data"] <-- try changing this line

file array giving different result for different browser

I am uploading a file in cake php.
<?php echo $form->create("Video",array('action'=>'add','name'=>'thisform','enctype'=>'multipart/formdata','onsubmit'=>'javascript: return validate();'));
echo $form->input("file_name",array('type'=>'file','id'=>'file_name','label'=>'','div'=>''));
echo $form->end();?>
In chrome I am getting the below
Array(
[Video] => Array(
[file_name] => Array(
[name] => imp.txt
[type] => text/plain
[tmp_name] => D:\xampp\tmp\php63.tmp
[error] => 0
[size] => 1568
)
)
)
But in mozilla i am getting the below
Array(
[Video] => Array(
[file_name] =>
)
)
As I was using
'enctype'=>'multipart/formdata' ;it was not working in mozilla.
But when I write
'enctype'=>'multipart/form-data' and it works.

Resources