Created
March 19, 2019 20:51
-
-
Save dura0ok/fc5c2f657228d444216e1219fdfbafa7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Category extends Model | |
{ | |
protected $guarded = []; | |
public function shops(){ | |
return $this->hasMany(Shop::class, 'category_id'); | |
} | |
public function shoplocations() | |
{ | |
return $this->hasManyThrough(Shoplocation::class, Shop::class); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('v2.layout.index') | |
@section('title', 'Почетный житель.РФ') | |
@section('head') | |
<script src="https://api-maps.yandex.ru/2.1/?apikey=a26b77ce-25b7-4d0c-aa26-161e16fa6b94&lang=ru_RU" | |
type="text/javascript" defer> | |
</script> | |
@endsection | |
@section('content') | |
@include ('v2.index.parts.promo') | |
@include ('v2.index.parts.deals') | |
@include ('v2.index.parts.profits') | |
@include ('v2.index.parts.searchorcreate') | |
@include ('v2.index.parts.companies') | |
@include ('v2.index.parts.map') | |
@include ('v2.index.parts.faq') | |
@endsection | |
@section('scripts') | |
<script> | |
var coords = [ | |
@foreach($mapPoints as $point) | |
{ | |
coords: [{{ $point->lat }}, {{ $point->long }}], | |
hint: "{{ $point->shop->name }}", | |
contentHeader: "{{ $point->shop->name }}", | |
type: "islands#blackStretchyIcon" | |
}, | |
@endforeach | |
]; | |
</script> | |
<script defer src="{{ asset('js/yamaps.js') }}"></script> | |
@endsection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\v2; | |
use App\Banner; | |
use App\Category; | |
use App\Faq; | |
use App\Shop; | |
use App\Shoplocation; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Support\Facades\DB; | |
class IndexController extends Controller | |
{ | |
public function index(Request $request) | |
{ | |
$companies = Shop::byCity($request) | |
->visible() | |
->orderBy('rating', 'desc') | |
->orderBy('id', 'desc') | |
->limit(8) | |
->get(); | |
$categories = Category::with('shops', 'shoplocations')->get(); | |
$faqs = Faq::isVisible()->get(); | |
$banners = Banner::byCity()->byVisibleBanners()->get(); | |
$mapPoints = Shoplocation::byCity($request)->orderBy('id', 'DESC') | |
->with('shop:id,name') | |
->limit(50)->get(); | |
dd(Shoplocation::all()); | |
return view('v2.index.index') | |
->with('companies', $companies) | |
->with('categories', $categories) | |
->with('faqs', $faqs) | |
->with('banners', $banners) | |
->with('mapPoints', $mapPoints); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Carbon\Carbon; | |
use Illuminate\Database\Eloquent\Builder; | |
use Illuminate\Database\Eloquent\Model; | |
/** | |
* Class Shop | |
* @package App | |
* @method visible() | |
*/ | |
class Shop extends Model | |
{ | |
protected $guarded = []; | |
protected $hidden = ['created_at', 'updated_at']; | |
protected $appends = ['logo_link']; | |
public function scopeVisible (Builder $builder) | |
{ | |
return $builder->where('is_visible', true); | |
} | |
public function user() | |
{ | |
return $this->belongsToMany(User::class); | |
} | |
public function logs() | |
{ | |
return $this->hasMany(DiscountLog::class); | |
} | |
public function city() | |
{ | |
return $this->belongsTo(City::class); | |
} | |
public function category() | |
{ | |
return $this->belongsTo(Category::class); | |
} | |
public function discounts() | |
{ | |
return $this->hasMany(Discount::class); | |
} | |
public function assignCategory($id) | |
{ | |
$this->category_id = $id; | |
$this->save(); | |
} | |
public function sellers() | |
{ | |
return $this->belongsToMany(User::class)->withPivot(['role']); | |
} | |
public function links() | |
{ | |
return $this->hasMany(ShopLink::class); | |
} | |
public function getRightsById($id) | |
{ | |
return $this->sellers()->where('users.id', $id)->first()->pivot->role; | |
} | |
public function locations() | |
{ | |
return $this->hasMany(Shoplocation::class); | |
} | |
public function files() | |
{ | |
return $this->belongsToMany(File::class, 'shop_file', 'shop_id', 'file_id'); | |
} | |
public static function scopeByCity(Builder $builder) | |
{ | |
return $builder->where('city_id', request()->cookie('loc') ?? 1); | |
} | |
public function minDiscount(): ?int | |
{ | |
return $this->discounts()->orderBy('discount', 'ASC')->first()->discount; | |
} | |
public function maxDiscount(): ?int | |
{ | |
return $this->discounts()->orderBy('discount', 'DESC')->first()->discount; | |
} | |
public function logo() | |
{ | |
if ($this->logo_url == null) { | |
return null; | |
} else { | |
return config('filesystems.logosBare') . $this->logo_url; | |
} | |
} | |
public function getLogoLinkAttribute() | |
{ | |
if (!$this->logo_url) return null; | |
return config('app.url') . $this->logo(); | |
} | |
public function metas() | |
{ | |
return $this->hasMany(MetaTag::class, 'shop_id', 'id'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Http\Request; | |
class Shoplocation extends Model | |
{ | |
protected $guarded = []; | |
protected $hidden = ['created_at', 'updated_at', 'shop_id']; | |
public function shop() | |
{ | |
return $this->belongsTo(Shop::class); | |
} | |
public function scopeByCity($query) | |
{ | |
return $query->whereHas('shop', function ($query) { | |
return $query->where('city_id', request()->hasCookie('loc') ? request()->cookie('loc') : 1); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment