Русское сообщество разработки на PHP-фреймворке Laravel.
Ты не вошёл. Вход тут.
Страницы 1
Посоветуйте литературу какую-нибудь по Ларавелу!
Заранее спасибо!
Спасибо!Выручили! Респект!
Я в PHP человек недавний и для овладения им пишу Интернет Магазин на чистом PHP
Длинные спагети кода !
Есть сайт написанный на Ларавеле
Писал когда-то мой знакомый!
Не могу разобраться как сделать сортировку товара по названию а не по ID
@section('content')
{{ HTML::style('/js/fancybox/jquery.fancybox-1.3.4.css') }}
{{ HTML::style('/js/trackbar/trackbar.css') }}
{{ HTML::style('/css/custom/brand.css') }}
{{ HTML::script('/js/trackbar/jquery-1.2.3.min.js') }}
{{ HTML::script('/js/trackbar/jquery.trackbar.js') }}
<script type="text/javascript">
$(document).ready(function(){
$('#blocktrackbar').trackbar({
onMove : function(){
document.getElementById("min-price").value = this.leftValue;
document.getElementById("max-price").value = this.rightValue;
},
width :160,
leftLimit : 500000,
leftValue : 300000,
rightLimit :10000000,
rightValue :8000000,
roundUp :100000
});
});
</script>
<section id="brand" class="content">
<div class="row rows">
@if ($result && !$result->isEmpty())
<div id="title">{{ $result->get(0)->brand->name }}</div>
<hr />
<div id="links" class="col-md-12">
<a href="{{ Request::root() . '/brand/' . $result->get(0)->brand->slag_name . '/male' }}">Мужские</a>
<a href="{{ Request::root() . '/brand/' . $result->get(0)->brand->slag_name . '/female' }}">Женские</a>
</div>
<aside id="products-container" class="col-md-8">
@foreach ($result as $product)
<div class="col-md-4 product">
@if ($product->nalichie == 1)
<h4 id="nalichie">В наличии </h4>
@else
<h4 id="nalichienet">Под заказ </h4>
@endif
<a href="{{ Request::root() }}/details/{{ $product->id }}">
{{ HTML::image('/img/prod_img/' . $product->main_image, '', array('class' => 'main-image')) }}
</a>
@if (!is_null($product->brand->sale))
{{ HTML::image('/img/sales/' . $product->brand->sale . '.png', '', array('class' => 'sale-img')) }}
@endif
<span class="prod-name">{{ $product->brand->name }}
{{ $product->name }}</span>
<h5> Интернет маг.<font style="margin-left: 7px;"><strong><font style="text-decoration:underline red; ">{{ $product->price }}</font></strong> руб.</font></h5>
<h5> Розничный маг.<strong>{{ $product->pricemag }}</strong> руб.</h5>
<div class="button-wrapper">
<button class="btn btn-primary buy hidden" data-prod-id="{{ $product->id }}">
Купить
</button>
</div>
</div>
@endforeach
<div id="paginate">{{ $result->links() }}</div>
</aside>
<aside id="filters">
{{ Form::open(array('url' => Request::url()."/filters")) }}
<div id="filters-title"><center>Выбор по параметрам:</center></div>
<div id="filters-price" class="filters-item">
<label>Розничная цена</label><br />
<input type="text" id="min-price" name="min-price" class="form-control input-sm" />
<div class="spring"></div>
<input type="text" id="max-price" name="max-price" class="form-control input-sm" />
<div id="blocktrackbar">trackbar</div>
</div>
<!-- <div class="hidden-filters"> -->
<div id="filters-diameter" class="filters-item">
<label>Диаметр</label><br />
<input type="text" name="min-diameter" class="form-control input-sm left" />
<div class="spring"></div>
<input type="text" name="max-diameter" class="form-control input-sm right" />
</div>
<div id="filters-thickness" class="filters-item">
<label>Толщина</label><br />
<input type="text" name="min-thickness" class="form-control input-sm left" />
<div class="spring"></div>
<input type="text" name="max-thickness" class="form-control input-sm right" />
</div>
<!-- </div> -->
@foreach ($open_filters as $filter)
<div id="{{ 'filters-' . $filter->ascii_name }}" class="filters-item">
<label class="filter-name">{{ $filter->name }}</label><br />
<div class="checkboxses">
@foreach ($filter->option_values as $value)
<input type="checkbox" name="{{ $filter->ascii_name . '[]' }}" value="{{ $value->ascii_name }}" />
<span>{{ $value->name }}</span><br />
@endforeach
</div>
</div>
@endforeach
<br />
<!-- <span id="show-flters">Показать больше фильтров</span> -->
<div class="hidden-filters">
@foreach ($hidden_filters as $filter)
<div id="{{ 'filters-' . $filter->ascii_name }}" class="filters-item">
<label class="filter-name">{{ $filter->name }}</label><br />
<div class="checkboxses">
@foreach ($filter->option_values as $value)
<input type="checkbox" name="{{ $filter->ascii_name . '[]' }}" value="{{ $value->ascii_name }}" />
<span>{{ $value->name }}</span><br />
@endforeach
</div>
</div>
@endforeach
<span id="hide-flters">Скрыть дополнительные фильтры</span>
</div>
<input id="submit" type="submit" value="Показать" />
<input id="reset" type="reset" value="Сбросить" />
{{ Form::close() }}
</aside>
@else
<h1>Здесь пока ничего нет</h1>
@endif
</div>
@include ('modals.added-to-cart')
{{ HTML::script('/js/custom/brand.js') }}
</section>
@show
И КОД контроллера
?php
namespace Controllers\Front;
use Illuminate\Database\Eloquent\Collection;
class BrandController extends BaseController {
/**
* @var string
*/
private $brand_name;
/**
* Constructor
*/
public function __construct()
{
$this->defineLayout();
}
/**
* Render page with all products by brand
*
* @param string $brand - product brand
*
* @return void
*/
public function allProducts($brand)
{
$result = $this->getProducts($brand);
$hidden_filters = $this->getHiddenFilters();
$open_filters = $this->getOpenFilters();
$this->brand_name = \Brand::where('slag_name', $brand)->first()->name;
if ($result && !$result->isEmpty()) {
$this->keywords .= ", $this->brand_name";;
}
$crumb = array($this->brand_name => \Request::root() . "/$brand");
\View::share('keywords', $this->keywords);
\View::share('breadcrumbs', $crumb);
$this->layout->nest('content', 'public.brand',
array(
'result' => &$result,
'brand' => $brand,
'hidden_filters' => &$hidden_filters,
'open_filters' => &$open_filters,
)
);
}
/**
* Get products by brand
*
* @param string $brand
*
* @return mixed
*/
private function getProducts($brand)
{
$result = \Product::where('brand_id', \Brand::where('slag_name', $brand)->first()->id)->paginate(30);
return (is_null($result)) ? false : $result;
}
/**
* Get products by brand and gender
*
* @param string $brand
* @param string $gender
*
* @return void
*/
public function getGenderProducts($brand, $gender)
{
$brand_id = \Brand::where('slag_name', $brand)->first()->id;
$hidden_filters = $this->getHiddenFilters();
$open_filters = $this->getOpenFilters();
$this->brand_name = \Brand::where('slag_name', $brand)->first()->name;
$result = \Product::where('brand_id', \Brand::where('slag_name', $brand)->first()->id)
->where('gender', $gender)
->paginate(50);
$crumb = array($this->brand_name => \Request::root() . "/brand/$brand");
if ($gender == 'male') {
$crumb['Мужские часы'] = \Request::root() . "/brand/$brand/$gender";
} else {
$crumb['Женские часы'] = \Request::root() . "/brand/$brand/$gender";
}
\View::share('keywords', $this->keywords);
\View::share('breadcrumbs', $crumb);
$this->layout->nest('content', 'public.brand',
array(
'result' => &$result,
'brand' => $brand,
'hidden_filters' => &$hidden_filters,
'open_filters' => &$open_filters
)
);
}
/**
* Get products with user filters
*
* @param string $brand - brand name
*
* @return void
*/
public function getWithFilters($brand, $gender = null)
{
$filters = \Input::all();
$filters = $this->cleanFilters($filters);
$this->brand_name = \Brand::where('slag_name', $brand)->first()->name;
$crumb = array(
$this->brand_name => \Request::root() . "/brand/$brand"
);
$brand = \Brand::where('slag_name', $brand)
->with(
array(
'products' => function($query) use ($gender) {
if (!is_null($gender)) {
$query->where('gender', $gender);
}
}
)
)
->get();
// apply filters
$result = $this->applyFilters($filters, $brand);
$hidden_filters = $this->getHiddenFilters();
$open_filters = $this->getOpenFilters();
\View::share('breadcrumbs', $crumb);
$this->layout->nest('content', 'public.filter',
array(
'result' => &$result,
'brand' => $brand,
'hidden_filters' => &$hidden_filters,
'open_filters' => &$open_filters
)
);
}
// primer
public function getNalichieProducts($brand, $nalichie)
{
$brand_id = \Brand::where('slag_name', $brand)->first()->id;
$hidden_filters = $this->getHiddenFilters();
$open_filters = $this->getOpenFilters();
$this->brand_name = \Brand::where('slag_name', $brand)->first()->name;
$result = \Product::where('brand_id', \Brand::where('slag_name', $brand)->first()->id)
->where('nalichie', $nalichie)
->paginate(50);
$crumb = array($this->brand_name => \Request::root() . "/brand/$brand");
if ($nalichie == '1') {
$crumb['В наличии'] = \Request::root() . "/brand/$brand/$nalichie";
} else {
$crumb['Под заказ'] = \Request::root() . "/brand/$brand/$nalichie";
}
\View::share('keywords', $this->keywords);
\View::share('breadcrumbs', $crumb);
$this->layout->nest('content', 'public.brand',
array(
'result' => &$result,
'brand' => $brand,
'hidden_filters' => &$hidden_filters,
'open_filters' => &$open_filters
)
);
}
// primer
/**
* Apply user filters for products
*
* @param array $filters - user filters
* @param Collection $brand - products by brand
*
* @return Collection
*/
private function applyFilters(array &$filters, Collection &$brand)
{
$keys = array_keys($filters);
$values = array_values($filters);
$result = new Collection();
foreach ($brand as $product) {
foreach ($product->products as $item) {
$options = \ProductOption::where('product_id', $item->id)->get()->toArray();
$this->checkOptions($keys, $values, $result, $options, $item);
}
}
return $result->unique();
}
/**
* Change products collection by users filters
*
* @param array $keys - options name
* @param array $values - options values
* @param Collection $result - collection for result
* @param array $ids - array with ids products in collection $result
* @param array $options - all option for current product
* @param Product $item - product for check
*
* @return void
*/
private function checkOptions(array &$keys, array &$values, Collection &$result, array &$options, \Product &$item)
{
foreach ($options as $option) {
foreach ($keys as $key) {
if (in_array($key, $option)) {
foreach ($values as $value) {
if (in_array($option['value_ascii_name'], $value)) {
$result->push($item);
}
}
}
}
}
}
/**
* Clean filters from filterform
*
* @param array $filters
*
* @return array
*/
private function cleanFilters(array $filters)
{
unset($filters['_token']);
foreach ($filters as $key => $value) {
if (!$value) {
unset($filters[$key]);
}
}
return $filters;
}
/**
* Get filters for products
*
* @return \Illuminate\Database\Eloquent\Collection
*/
private function getHiddenFilters() {
return \Option::where('id', '>', 2)
->where('main', null)
->with('option_values')
->get();
}
/**
* Get filters for products
*
* @return \Illuminate\Database\Eloquent\Collection
*/
private function getOpenFilters() {
return \Option::where('id', '>', 2)
->where('main', 1)
->with('option_values')
->get();
}
}
Страницы 1