php


How to display content (HTML) based on route paramater in Laravel 5.4


I'm new to Laravel and i'm working in a e-commerce application. In this app, it is needed to display all products in different pages (1, 2, 3, ... etc). The routes are: /products/1, /products/2, etc. I'm currently using the pattern of showing 10 products per page.
For example, if there are 31 products, there will be 4 pages (4 buttons in the bottom of the page).
1st page -> 10 products;
2nd page -> 10 products;
3rd page -> 10 products;
4th page -> 1 product;
My question here is how do I iterate in the database and spread these products in their respective routes. What I've done so far (using blade):
#extends("template")
#section("content")
#for($i = 0; $i < $number_of_buttons; $i++) <!-- iterate trough the number of buttons -->
#for($k = 0; $k < $NUMBER_OF_PRODUCTS_PER_PAGE; $k++) <!-- iterate trough all the products, but showing only a quantity of {{$NUMBER_OF_PRODUCTS_PER_PAGE}} products per page -->
<div class="row">
<div class="col-xs-6">
<img src="{{$products[$k]->image}}" class = "img-responsive" alt = "{{$products[$k]->name}}">
</div>
<div class="col-xs-6">
<h2>{{$products[$k]->name}}</h2>
<p>{{$products[$k]->description}} </p>
<p>{{$products[$k]->value}} </p>
Details
</div>
</div>
#endfor
#endfor
#stop
The logic itself seems kinda wrong, but how do I insert into each route the products? In the example above, all routes will have the same number of products. I want to know how do I especify in this code what each route will receive, if it is possible. If i'm not being clear enough, please let me know.
Pagination is exactly what I was looking for. I spent time thinking a logic to display all the products in pages lol. As i said I'm new to laravel therefore I did not know this method. Thanks #Ohgodwhy and #Scott
in your controller
$products = Product::paginate(10);
return View::make('pagination', compact('products'));
in your template
#extends("template")
#section("content")
#foreach($products as $product)
<div class="row">
<div class="col-xs-6">
<img src="{{$product->image}}" class = "img-responsive" alt = "{{$product->name}}">
</div>
<div class="col-xs-6">
<h2>{{$product->name}}</h2>
<p>{{$product->description}} </p>
<p>{{$product->value}} </p>
Details
</div>
</div>
#endforeach
<div class="pagination"> {{ $products->links() }} </div>
#stop

Related Links

Saving the Wordpress header to a php file accessible anywhere?
PHP - Would i need to create 2 separate objects to hold database data from 2 separate tables?
Can't get username in URL
Filtering an Array
How does php strtotime handle last sunday
Finding next fibonacci number
Custom Post Type loop WITH pagination on front-page.php
Login PHP doesn't select right user
What I doing wrong with Mockery
PHP Include Not Working in Cron Job
Different shipping method for different customer group in Magento
Handling multi-dimensional array in PHP
'Unsupported delete request.' removing photo tags via Facebook PHP SDK 4
Merged arrays are not in correct array format
Make <br> optional for the last line
Catchable Fatal Error: Argument 1 passed to \Entity\Image::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile,

Categories

HOME
google-chrome
jboss
freeradius
cucumber
qc
activex
google-sheets-query
log4j2
scrape
alljoyn
circleci
powermock
web-deployment
renderscript
psql
liferay-6.2
quantitative-finance
perfino
pyopencl
function-points
environment
plyr
strophe.js
macromedia
bonita
bitbake
knights-tour
appcode
android-canvas
nsuserdefaults
eclipse-gmf
google-now
assemblies
python-sounddevice
flowchart
coverage.py
bit-shift
swift2.3
viewmodel
gtk#
scala-collections
portability
nrf51
perl-data-structures
nitrousio
pjax
ndk-build
spring-mongo
perforce-integrate
textblock
okta-api
flush
pack
enunciate
boost-proto
python-cffi
decidable
ibm-was
nette
enaml
blockquote
uitest
darwin
bootstrap-wysiwyg
ampersand
dbmigrate
erlog
whitespace-language
sablecc
kognitio-wx2
utf8-decode
image-rotation
zend-mail
xcode6.3.1
siena
treeline
coding-efficiency
nachos
wso2bam
gpu-programming
jchartfx
jms-serializer
profiles
application-server
coalesce
libxml-js
objective-c-runtime
void-pointers
notin
daap
nsmutablestring
telerik-ajax
series-40
active-record-query
mongrel
tessellation
mysqli-multi-query
yahoo-maps
html-components
rtti
jboss-mdb
jvm-bytecode
synthesizer

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App