/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $names = ['Thỏa thuận', '< 500 triệu', '500 - 800 triệu', '800 triệu - 1 tỷ', '1 - 2 tỷ', '2 - 3 tỷ', '3 - 5 tỷ', '5 - 7 tỷ', '7 - 10 tỷ', '10 - 20 tỷ', '20 - 30 tỷ', '> 30 tỷ'];
     $from = [0, 0, 500000000, 800000000, 1000000000, 2000000000, 3000000000, 5000000000, 7000000000, 10000000000, 20000000000, 30000000000];
     $to = [0, 499999999, 800000000, 1000000000, 2000000000, 3000000000, 5000000000, 7000000000, 10000000000, 20000000000, 30000000000, 100000000000];
     foreach ($names as $key => $value) {
         $project_type = Price_range::create(['key' => Common::createKeyURL($value), 'name' => $value, 'from' => $from[$key], 'to' => $to[$key], 'priority' => $key, 'active' => 1, 'created_by' => 'vankhoeseed', 'updated_by' => 'vankhoeseed']);
     }
 }
 /**
  * List Price_range ajax.
  */
 public function getPriceRange(Request $request)
 {
     $object = Price_range::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
     return $object->toArray();
 }
    public function product_detail($product_id, $product_key)
    {
        $product = Product::findOrFail($product_id);
        if ($product != null) {
            $price_ranges = Price_range::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
            $area_ranges = Area_range::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
            $incense_types = Incense_type::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
            // metadata
            $site_title = $product->title . ' - ' . Config::findByKey('site_title')->first()->value;
            SEOMeta::setTitle($site_title);
            SEOMeta::setDescription($product->meta_description);
            SEOMeta::addKeyword([$product->meta_keywords]);
            SEOMeta::addMeta('product:published_time', $product->created_at->toW3CString(), 'property');
            if (isset($product->product_type->name)) {
                SEOMeta::addMeta('product:section', $product->product_type->name, 'property');
            }
            OpenGraph::setTitle($site_title);
            OpenGraph::setDescription($product->meta_description);
            OpenGraph::setUrl($product->getLink());
            OpenGraph::addProperty('type', 'product');
            OpenGraph::addProperty('locale', app()->getLocale());
            OpenGraph::addProperty('locale:alternate', ['vi-vn', 'en-us']);
            OpenGraph::addImage($product->getThumnail());
            OpenGraph::addImage($product->attachments->lists('path'));
            OpenGraph::addImage(['url' => Image::url($product->getThumnail(), 300, 300, array('crop')), 'size' => 300]);
            // end metadata
            $attachments = $product->attachments()->take(5)->get();
            $wards = $product->district->wards;
            $heading = $product->product_type->name . ' ' . (isset($product->ward_id) && $product->ward_id > 0 ? $product->ward->name : $product->district->name);
            // $link ='';
            if (isset($product->ward_id) && $product->ward_id > 0) {
                $link = route('product_type_province_district_ward', ['product_type_key' => $product->product_type->key, 'province_key' => $product->province->key, 'district_key' => $product->district->key, 'ward_key' => $product->ward->key]);
                $relate_products = $product->ward->products()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take(5)->get();
                if (count($relate_products) == 0) {
                    $relate_products = $product->district->products()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take(5)->get();
                }
            } else {
                $link = route('product_type_province_district', ['product_type_key' => $product->product_type->key, 'province_key' => $product->province->key, 'district_key' => $product->district->key]);
                $relate_products = $product->district->products()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take(5)->get();
            }
            $breadcrumb = '<ul class="breadcrumb pull-left padl0"> 
			<li class="active"><a href="' . route('homepage') . '">Trang chủ</a></li> 
			<li class="active"><a href="' . route('products') . '">Căn hộ</a></li> 
			<li class="active"><a href="' . route('product_type', ['product_type_key' => $product->product_type->key]) . '">' . $product->product_type->name . '</a></li> 
			<li class="active"><a href="' . route('product_type_province', ['product_type_key' => $product->product_type->key, 'province_key' => $product->province->key]) . '">' . $product->province->name . '</a></li> 
			<li class="active"><a href="' . route('product_type_province_district', ['product_type_key' => $product->product_type->key, 'province_key' => $product->province->key, 'district_key' => $product->district->key]) . '">' . $product->district->name . '</a></li> 
			' . (isset($product->ward_id) && $product->ward_id > 0 ? '<li class=""><a href="' . $link . '">' . $product->ward->name . '</a></li> ' : '') . '
			</ul>';
            return view('frontend.sites1.product_detail', ['product' => $product, 'attachments' => $attachments, 'product_type' => $product->product_type, 'wards' => $wards, 'price_ranges' => $price_ranges, 'area_ranges' => $area_ranges, 'incense_types' => $incense_types, 'relate_products' => $relate_products, 'search_type' => 'product_detail', 'link' => $link, 'breadcrumb' => $breadcrumb, 'heading' => $heading]);
        } else {
            return view('frontend.sites1.product_detail');
        }
    }