@MWDeveloper
public function index($kind, Request $request)
{
$kind = Categories::where('path', $kind)->first();
if($kind == NULL or $kind->type == 'producer' or $kind == FALSE)
{
return abort(404);
} else {
$producers = Categories::find($kind->id);
// $products = Products::where('kind_id', $kind->id)->orderBy('product_order', 'desc')->paginate(12);
$brands = Input::has('brands') ? Input::get('brands') : null;
$products = Products::where('kind_id', $kind->id)->where(function($query){
$brands = Input::has('brands') ? Input::get('brands') : null;
if(isset($brands)){
foreach ($brands as $brand) {
$query->orWhere('producer_id', '=', $brand);
}
}
})->orderBy('product_order', 'desc')->paginate(12);
return view('categories.index', compact(['products']))
->with('category', $kind)
->with('producers', $producers)->withInput(Input::all());
}
}
HTML
@section('page_title'){{ $category->title }}@stop.
@section('content')
@include('pagination', ['paginator' => $products])
@foreach($products as $data)
{{ $data->title }}
{{ $data->description }}
...
@endforeach
@stop
Model
class Products extends Model
{
public $timestamps = false;
protected $table = 'products';
protected $fillable = ['title', 'path', 'preview', 'short_description', 'price', 'usd', 'parent_type', 'producer_id'];
public function value()
{
return $this->hasOne('App\Values', 'product_id');
}
public function producer()
{
return $this->belongsTo('App\Categories', 'producer_id');
}
public function kind()
{
return $this->belongsTo('App\Categories', 'kind_id');
}
public function images()
{
return $this->hasMany('App\Images', 'product_id');
}
}