Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FirmanWahyudi007 committed May 30, 2022
2 parents df9a78e + d29c597 commit 0e11874
Show file tree
Hide file tree
Showing 16 changed files with 3,435 additions and 647 deletions.
26 changes: 26 additions & 0 deletions app/Http/Controllers/User/KamarKostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Controllers\User;

use App\Models\KamarKost;
use App\Models\LokasiKost;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class KamarKostController extends Controller
{
/**
* Menampilkan kamar kost
*
* @param [int] $id
* @return void
*/
public function index($id){

$kamar = KamarKost::with('gambarkamars')->where('id', $id)->first();

return view('user.KamarKost', [
'kamar' => $kamar,
]);
}
}
95 changes: 95 additions & 0 deletions app/Http/Controllers/User/TempatKostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Http\Controllers\User;

use App\Models\KamarKost;
use App\Models\LokasiKost;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class TempatKostController extends Controller
{
/**
* Menampilkan list tempat kost beserta harga kamar termurah dan termahal
*
* @return View
*/
public function index(){

$tempatKosts = DB::table('lokasi_kosts')->select('lokasi_kosts.*',
DB::raw('(SELECT kamar_kosts.harga from kamar_kosts
WHERE kamar_kosts.lokasi_kost_id = lokasi_kosts.id
ORDER BY harga ASC LIMIT 1) as kamar_termurah'),
DB::raw('(SELECT kamar_kosts.harga from kamar_kosts
WHERE kamar_kosts.lokasi_kost_id = lokasi_kosts.id
ORDER BY harga DESC LIMIT 1) as kamar_termahal'),
)->get();

return view('user.tempatKostMobile', [
'tempatKosts' => $tempatKosts,
]);
}

/**
* Menampilkan list kamar yang ada pada tempat kosts
*
* @param [int] $id
* @return View
*/
public function show($id){

$tempat = LokasiKost::where('id', $id)->first();
$kamars = KamarKost::with('gambarkamar')->where('lokasi_kost_id', $id)->get();
$fasilitas_all = KamarKost::select('fasilitas')->where('lokasi_kost_id', $id)->get();
$fasilitas_unique = [];

foreach ($fasilitas_all as $item) {
$fasilitas_unique = array_unique(array_merge($fasilitas_unique, $item['fasilitas']));
}

return view('user.tempatKostView', [
'tempat' => $tempat,
'kamars' => $kamars,
'fasilitas_unique' => $fasilitas_unique
]);
}

/**
* Sama seperti fungsi index, tetapi dengan filter
* Ini digunakan untuk fungsi jquery agar tidak perlu reload
*
* @param Request $request
* @return View
*/
public function listFilter(Request $request){

$urut = $request->urut;
$maxHarga = $request->maxHarga;
$minHarga = $request->minHarga;

$tempatKosts = DB::table('lokasi_kosts')->select('lokasi_kosts.*',
DB::raw('(SELECT kamar_kosts.harga from kamar_kosts
WHERE kamar_kosts.lokasi_kost_id = lokasi_kosts.id
ORDER BY harga ASC LIMIT 1) as kamar_termurah'),
DB::raw('(SELECT kamar_kosts.harga from kamar_kosts
WHERE kamar_kosts.lokasi_kost_id = lokasi_kosts.id
ORDER BY harga DESC LIMIT 1) as kamar_termahal'),
)
->when($urut, function ($query, $urut) {
return $query->orderBy('kamar_termurah', $urut);
})
->when($maxHarga, function ($query, $maxHarga) {
return $query->havingRaw("kamar_termurah < $maxHarga");
})
->when($minHarga, function ($query, $minHarga) {
return $query->havingRaw("kamar_termurah > $minHarga");
})
->get();

return view('user.tempatKostItem', [
'tempatKosts' => $tempatKosts,
]);
}

}
6 changes: 6 additions & 0 deletions app/Models/KamarKost.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function gambarkamars()
return $this->hasMany(GambarKamar::class);
}

public function gambarkamar()
{
# code...
return $this->hasOne(GambarKamar::class)->latestOfMany();
}

/**
* Set the fasilitas
*
Expand Down
3 changes: 2 additions & 1 deletion app/Models/LokasiKost.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LokasiKost extends Model
public function kamarkost()
{
# code...
$this->hasMany(KamarKost::class);
return $this->hasMany(KamarKost::class);
}

}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
Expand Down
Loading

0 comments on commit 0e11874

Please sign in to comment.