Hello, I have this similar code in my 3 controllers, How can i make this code more beautiful?? Thank you very much
protected function getCurrentViolation($last, $first){
$select = array('ticket_no', 'plate_no', 'dlicense_no', 'dLast_name', 'dfirst_name', 'dmiddle_name', 'apprehending_date', 'apprehending_place', 'afirst_name', 'amiddle_name', 'alast_name', 'time_of_violation', 'specific', 'descriptions', 'second_degree_offense', 'first_degree_offense', 'third_degree_offense', 'payment_status');
if(Input::has('first')){
$result = DB::table('driver')
->Join('ticket', 'driver.id', '=', 'ticket.fktd_id')
->join('employee', 'ticket.fkta_id', '=', 'employee.id')
->join('ticket_line', 'ticket.ticket_no', '=', 'ticket_line.fkt_ticket_no')
->join('violation' , 'ticket_line.fkt_id', '=', 'violation.id')
->join('vehicle', 'ticket.fkt_plate', '=' ,'vehicle.plate_no')
->where('dLast_name', '=', Input::get('last'))
->where('dfirst_name', '=', Input::get('first'))
// ->where('payment_status', '=', 'Paid')
->select($select)
->orderBy('dLast_name')
->get();
return $result;
}
if(Input::has('last')){
$result = DB::table('driver')
->Join('ticket', 'driver.id', '=', 'ticket.fktd_id')
->join('employee', 'ticket.fkta_id', '=', 'employee.id')
->join('ticket_line', 'ticket.ticket_no', '=', 'ticket_line.fkt_ticket_no')
->join('violation' , 'ticket_line.fkt_id', '=', 'violation.id')
->join('vehicle', 'ticket.fkt_plate', '=' ,'vehicle.plate_no')
->where('dLast_name', '=', Input::get('last'))
// ->where('payment_status', '=', 'Paid')
->select($select)
->orderBy('dLast_name')
->get();
return $result;
}
}
I have this lines of code in my 3 controller,
Create a repository that represents the Ticket. It holds all your persistence related logic. You could create a method on it called getTicketByName() and pass your input. Just inject into your controllers, and call the method.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community