public function parseRents( $rents ) { try { $client = Client::find(array('phone'=>$rents[7])); $inventory = Inventories::find( array('number'=>$rents[3]) ); $shift = null; $date = $this->searchDate( $rents[0] ); if(!is_null($date) ) $shift = Shift::find(array('shiftDate'=>$date)); $idInventory = -1; $idClient = -1; $idShift = -1; if ( !is_null($inventory) ) $idInventory = $inventory->id; if ( !is_null($client) ) $idClient = $client->id; if ( !is_null($shift) ) { $idShift = $shift->id; //echo $idShift."<br>"; } Rent::create( array( 'start'=>$rents[1], 'end'=>$rents[2], 'idInventory'=>$idInventory, 'idClient'=>$idClient, 'expense'=>$rents[22], 'idShift'=>$idShift ) ); } catch (\exception $e) { //echo "Exception in parseRents <br>"; echo $e->getMessage()."<br>"; } }