示例#1
0
 public function getAll()
 {
     $columns = array('address' => 'Property Address', 'last_name' => 'Last Name', 'first_name' => 'First Name', 'renter_id' => 'Renter ID', 'term_start' => 'Start Date', 'term_end' => 'End Date', 'rent' => 'Rent');
     $contracts = Contract::join('renters', 'contracts.renter_id', '=', 'renters.id')->join('properties', 'contracts.property_id', '=', 'properties.id')->select('properties.address', 'renters.first_name', 'renters.last_name', 'contracts.*')->get();
     return view('contracts.index', compact('contracts', 'columns'));
 }
 public function filterContractsByCarOrDriver($search)
 {
     $reg_no = substr($search, 0, strpos($search, 'or'));
     $driver_name = substr($search, strpos($search, 'or') + 2);
     if (strpos($driver_name, '-') > 0) {
         //swap
         $temp = $driver_name;
         $driver_name = $reg_no;
         $reg_no = $temp;
     }
     //dd(['1'=>$reg_no,'2'=>$driver_name]);
     $collection = Contract::join('cars', 'contracts.car_id', '=', 'cars.id')->join('drivers', 'contracts.driver_id', '=', 'drivers.id')->where('cars.reg_no', 'LIKE', $reg_no)->orWhere('drivers.name', 'LIKE', $driver_name)->select('contracts.*')->get();
     return $collection;
 }