コード例 #1
0
ファイル: HistoryController.php プロジェクト: sl249/carRental
 public function view($type)
 {
     if (Auth::check()) {
         $cars = Car::all();
         if ($type == "open") {
             $sectionArray = array('Open');
             $rentals = Rental::where('state', 0)->where('user_id', Auth::user()->id)->get();
             if ($rentals->count()) {
                 //not empty
                 $empty = false;
             } else {
                 $empty = true;
             }
         } else {
             $sectionArray = array('Closed');
             $rentals = Rental::where('state', 1)->where('user_id', Auth::user()->id)->get();
             if ($rentals->count()) {
                 //not empty
                 $empty = false;
             } else {
                 $empty = true;
             }
         }
         return view('history.rentals', compact('rentals', 'cars', 'sectionArray'))->with('empty', $empty);
     } else {
         return Redirect::to('/');
     }
 }
コード例 #2
0
 public function customValidation()
 {
     //max rent day must be 3 days
     Validator::extend('checkMaxRentDay', function ($attribute, $value, $parameters, $validator) {
         //check if duration is > 3 days
         if (Input::get('date-from') != null && Input::get('date-to') != null) {
             $datefrom = Carbon::createFromFormat('Y-m-d', Input::get('date-from'));
             $dateto = Carbon::createFromFormat('Y-m-d', Input::get('date-to'));
             if ($datefrom->diffInDays($dateto) > 3) {
                 return false;
             }
         }
         return true;
     });
     //validation message replacer
     Validator::replacer('checkMaxRentDay', function ($attribute, $value, $parameters, $validator) {
         return 'Maximal rent day is 3 days';
     });
     //check car is already rented
     Validator::extend('checkRentedCar', function ($attribute, $value, $parameters, $validator) {
         if (Input::get('date-from') != null && Input::get('date-to') != null) {
             $rented = Rental::where('car-id', $value)->where('id', '<>', $parameters[0])->where('date-from', '<=', Input::get('date-to'))->where('date-to', '>=', Input::get('date-from'))->get();
             return $rented->isEmpty();
         }
         return true;
     });
     Validator::replacer('checkRentedCar', function ($attribute, $value, $parameters, $validator) {
         return 'Car still rented';
     });
     //check if client is renting a car in selected date
     Validator::extend('checkClientRent', function ($attribute, $value, $parameters, $validator) {
         if (Input::get('date-from') != null && Input::get('date-to') != null) {
             $clientrent = Rental::where('client-id', $value)->where('id', '<>', $parameters[0])->where('date-from', '<=', Input::get('date-to'))->where('date-to', '>=', Input::get('date-from'))->get();
             return $clientrent->isEmpty();
         }
         return true;
     });
     Validator::replacer('checkClientRent', function ($attribute, $value, $parameters, $validator) {
         return 'Client is still renting a car';
     });
 }
コード例 #3
0
ファイル: routes.php プロジェクト: arvinchs/RAI_Task_5
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('relasi-1', function () {
    $anggota = Anggota::where('nama', '=', 'Arvin Chendriyana Supriyadi')->first();
    return $anggota->detailanggota->alamat;
});
Route::get('relasi-2', function () {
    $anggota = Anggota::where('nama', '=', 'Arvin Chendriyana Supriyadi')->first();
    return $anggota->rental->nama;
});
Route::get('relasi-3', function () {
    $rental = Rental::where('nama', '=', 'Hanzo')->first();
    foreach ($rental->anggota as $temp) {
        echo '<li> Nama : ' . $temp->nama . '</li>';
    }
});
Route::get('relasi-4', function () {
    $arvin = Anggota::where('nama', '=', 'Arvin Chendriyana Supriyadi')->first();
    foreach ($arvin->game as $temp) {
        echo '<li>' . $temp->judul . '</li>';
    }
});
Route::get('relasi-5', function () {
    $fallout_4 = Game::where('judul', '=', 'Fallout 4')->first();
    foreach ($fallout_4->anggota as $temp) {
        echo '<li> Nama : ' . $temp->nama . '</li>';
    }