如何获取通过url传递的id并将其保存在输入中?控制器是这样的:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use URL;
use DB;
class productController extends Controller
{
//
public function getIndex(){
$in=URL::get('id');
$product=DB::table('products')->get(['id','name','salary','sale','p_salary','n_salary','best','type','image_name','category_id','sub_id','incategory_id','new']);
return view('contents.products')->with('product',$product)
->with('in',$in);
}
}
,视图就是这样:
@extends('master')
@section('content')
<form method="POST" action="{{action('productController@getIndex')}}" enctype="multipart/form-code">
{!! csrf_field() !!}
<div class="em-wrapper-main">
<div class="container container-main">
<div class="em-inner-main">
<div class="em-wrapper-area02"></div>
<div class="em-wrapper-area03"></div>
<div class="em-wrapper-area04"></div>
<div class="em-main-container em-col1-layout">
<div class="row">
<div class="em-col-main col-sm-24">
<div class="page-title category-title">
<h1>Shoes</h1>
</div>
<div class="category-products">
<div class="toolbar-top">
<div class="toolbar">
<div class="pager">
<p class="amount"> Items 1 to 12 of 20 total</p>
<div class="pages">
<ol>
<li class="current">1</li>
<li><a href="#">2</a>
</li>
<li>
<a class="next i-next" href="#" title="Next"> <img src="{{asset('assets/images/pager_arrow_right.gif')}}" alt="Next" class="v-middle" /> </a>
</li>
</ol>
</div>
</div><!-- /.pager -->
<div class="sorter">
<p class="view-mode">
<label>View as:</label> <strong title="Grid" class="grid">Grid</strong> <a href="category-one-column-list.html" title="List" class="list">List</a>
</p>
<div class="sort-by toolbar-switch">
<div class="toolbar-title">
<label>Sort By</label>
<select class="sortby" name="sortby">
<option value="position" selected="selected"> Position</option>
<option value="name"> Name</option>
<option value="price"> Price</option>
</select>
</div>
<a href="#" title="Set Descending Direction"><img src="{{asset('assets/images/i_asc_arrow.png')}}" alt="Set Descending Direction" class="v-middle" />
</a>
</div>
<div class="limiter toolbar-switch">
<div class="toolbar-title">
<label>Show</label>
<select class="toolbar-show">
<option value="12" selected="selected"> 12</option>
<option value="24"> 24</option>
<option value="36"> 36</option>
</select>
</div>
</div>
</div><!-- /.sorter -->
</div>
</div><!-- /.toolbar-top -->
<div id="em-grid-mode">
<ul class="emcatalog-grid-mode products-grid emcatalog-disable-hover-below-mobile">
@foreach($product as $p)
@foreach($in as $n)
@if($p->incategory_id == $n->id)
<li class="item first">
<div class="product-item">
<div class="product-shop-top">
<a href="{{action('productdetailController@getProduct' , array('id' => $p->id))}}" title="{{$p->name}}" class="product-image">
<img class="em-img-lazy img-responsive em-alt-hover" src="{{asset('images/')}}/{{$p->image_name}}" width="220" height="220" alt="WIASSI Version 1" />
<img id="product-collection-image-206" class="em-img-lazy img-responsive em-alt-org" src="{{asset('images/')}}/{{$p->image_name}}" width="220" height="220" alt="WIASSI Version 1" />
<span class="bkg-hover"></span> </a>
<div class="bottom">
<div class="em-btn-addto text-center ">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="206"><span><span>Add to Cart</span></span>
</button>
<ul class="add-to-links">
<li><button type="submit" class="link-wishlist" name="submit" title="Add to Wishlist">Add to Wishlist</button>
</li>
<li><a href="#206" class="link-compare" title="Add to Compare">Add to Compare</a>
</li>
</ul>
</div>
<div class="quickshop-link-container"> <a href="#" class="quickshop-link" title="Quickshop">Quickshop</a>
</div>
</div>
</div>
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name text-center "><a href="product_detail" title="{{$p->name}}"> {{$p->name}} </a></h2>
<div class=" text-center">
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:%"></div>
</div> <span class="amount"><a href="#" onclick="206">(0)</a></span>
</div>
</div>
<div class="text-center ">
<div class="price-box"> <span class="regular-price" id="product-price-206"> <span class="price" content="{{$p->salary}}">${{$p->salary}}</span> </span>
</div>
</div>
<div class="desc std text-center em-element-display-hover">{{$p->name}}</div>
</div>
</div>
</div><!-- /.product-item -->
</li>
@endif
@endforeach
@endforeach
</ul>
</div><!-- /.em-grid-mode -->
<div class="toolbar-bottom em-box-03">
<div class="toolbar">
<div class="pager">
<p class="amount"> Items 1 to 12 of 20 total</p>
<div class="pages">
<ol>
<li class="current">1</li>
<li><a href="#">2</a>
</li>
<li>
<a class="next i-next" href="#" title="Next">
<img src="{{asset('assets/images/pager_arrow_right.gif')}}" alt="Next" class="v-middle" /> </a>
</li>
</ol>
</div>
</div><!-- /.pager -->
<div class="sorter">
<p class="view-mode">
<label>View as:</label> <strong title="Grid" class="grid">Grid</strong> <a href="category-one-column-list.html" title="List" class="list">List</a>
</p>
<div class="sort-by toolbar-switch">
<div class="toolbar-title">
<label>Sort By</label>
<select class="sortby" name="sortby">
<option value="position" selected="selected"> Position</option>
<option value="name"> Name</option>
<option value="price"> Price</option>
</select>
</div>
<a href="#" title="Set Descending Direction"><img src="{{asset('assets/images/i_asc_arrow.png')}}" alt="Set Descending Direction" class="v-middle" />
</a>
</div>
<div class="limiter toolbar-switch">
<div class="toolbar-title">
<label>Show</label>
<select class="toolbar-show">
<option value="12" selected="selected"> 12</option>
<option value="24"> 24</option>
<option value="36"> 36</option>
</select>
</div>
</div>
</div><!-- /.sorter -->
</div>
</div><!-- /.toolbar-bottom -->
</div><!-- /.category-products -->
</div>
</div>
</div><!-- /.em-main-container -->
</div>
</div>
</div><!-- /.em-wrapper-main -->
</form>
@stop
如何获取通过url传递incategory_id的产品?
答案 0 :(得分:2)
您可以使用rax
外观获取Request
,然后使用id
方法获取请求where
,如下所示:
product
此外,您可以<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Request;
use DB;
class productController extends Controller
{
public function getIndex()
{
$in=Request::get('id');
$product=DB::table('products')->where('incategory_id', $in)->get(['id','name','salary','sale','p_salary','n_salary','best','type','image_name','category_id','sub_id','incategory_id','new']);
return view('contents.products')->with('product',$product);
}
}
type-hint
:
Illuminate\Http\Request