/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $project_types = ['Căn hộ chung cư', 'Khu biệt thự', 'Cao ốc văn phòng', 'Khu thương mại', 'Khu dân cư', 'Nhà ở xã hội', 'Khu đô thị mới'];
     $project_types_meta_description = ['Căn hộ chung cư', 'Khu biệt thự', 'Cao ốc văn phòng', 'Khu thương mại', 'Khu dân cư', 'Nhà ở xã hội', 'Khu đô thị mới'];
     $project_types_meta_keywords = ['Căn hộ chung cư', 'Khu biệt thự', 'Cao ốc văn phòng', 'Khu thương mại', 'Khu dân cư', 'Nhà ở xã hội', 'Khu đô thị mới'];
     foreach ($project_types as $key => $value) {
         $project_type = Project_type::create(['key' => Common::createKeyURL($value), 'name' => $value, 'priority' => $key, 'meta_description' => $project_types_meta_description[$key], 'meta_keywords' => $project_types_meta_keywords[$key], 'active' => 1, 'created_by' => 'vankhoe', 'updated_by' => 'vankhoe']);
     }
 }
 public function getProjectsByTypeKey($typeKey = '', $limit = 0)
 {
     $project_type = Project_type::where('key', $typeKey)->first();
     if (isset($project_type) && !is_null($project_type)) {
         if ($limit == 0) {
             return $project_type->projects()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
         } else {
             return $project_type->projects()->where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->take($limit)->get();
         }
     }
     return [];
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     DB::transaction(function () use($id) {
         $user = Auth::user();
         $project_type = Project_type::findOrFail($id);
         $project_type->updated_by = $user->name;
         $project_type->deleted_by = $user->name;
         $project_type->key = $project_type->key . '-' . microtime(true);
         $project_type->save();
         // soft delete
         $project_type->delete();
     });
 }
 /**
  * List Project type ajax.
  */
 public function getProjectType(Request $request)
 {
     $project_types = Project_type::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->get();
     return $project_types->toArray();
 }
    /**
     * PROJECT_TYPE vs PROVINCE vs DISTRICT vs WARD
     */
    public function project_type_province_district_ward($project_type_key, $province_key, $district_key, $ward_key, Request $request)
    {
        $ward = Ward::findByKey($ward_key)->first();
        if (is_null($ward)) {
            $ward = Ward::where('is_publish', 1)->orderBy('priority')->orderBy('created_at', 'desc')->first();
        }
        $district = $ward->district;
        $province = $district->province;
        $limit = Config::findByKey('rows_per_page_project')->first()->value;
        $project_type = Project_type::findByKey($project_type_key)->first();
        if (is_null($project_type)) {
            $project_type = Project_type::where('active', 1)->orderBy('priority')->orderBy('created_at', 'desc')->first();
        }
        $projects = Project::where('project_type_id', $project_type->id)->where('district_id', $district->id)->where('active', 1);
        $projects = $projects->orderBy('priority')->orderBy('created_at', 'desc')->paginate($limit);
        $searchDescription = $project_type->name . ' ' . $province->name . ' ' . $district->name . ' ' . $ward->name;
        $link = route('project_type_province_district_ward', ['project_type_key' => $project_type->key, 'province_key' => $province->key, 'district_key' => $district->key, 'ward_key' => $ward->key]);
        $breadcrumb = '<ul class="breadcrumb"> 
		<li class="active"><a href="' . route('homepage') . '">Trang chủ</a></li> 
		<li class="active"><a href="' . route('projects') . '">Dự án</a></li> 
		<li class="active"><a href="' . route('project_type', ['project_type_key' => $project_type->key]) . '">' . $project_type->name . '</a></li> 
		<li class="active"><a href="' . route('project_type_province', ['project_type_key' => $project_type->key, 'province_key' => $province->key]) . '">' . $province->name . '</a></li> 
		<li class="active"><a href="' . route('project_type_province_district', ['project_type_key' => $project_type->key, 'province_key' => $province->key, 'district_key' => $district->key]) . '">' . $district->name . '</a></li> 
		<li class=""><a href="' . $link . '">' . $ward->name . '</a></li> 
		</ul>';
        $heading = $project_type->name . ' ' . $province->name . ' ' . $district->name . ' ' . $ward->name;
        $projectCategory = new ProjectCategory();
        $projectsSpecial = $projectCategory->getProjectsByCategoryKey('du-an-noi-bat', 5);
        $this->setMetadata($searchDescription);
        return view('frontend.sites1.project_search', ['projects' => $projects, 'project_type' => $project_type, 'district' => $district, 'projectsSpecial' => $projectsSpecial, 'search_type' => 'project_type_province_district', 'link' => $link, 'searchDescription' => $searchDescription, 'breadcrumb' => $breadcrumb, 'heading' => $heading]);
    }