I am designing a simple ticketing system in Laravel 4. The system will simply allow a User to create a ticket, and an Administrator to answer it.
The User will be able to:
- View a list of his tickets.
- Create a new ticket.
- View the replies to one of his own ticket.
- Add a reply to a one of his own ticket.
- Close a one of his own ticket.
- Perform the above tasks via the url www.example.com/support
The Administrator will be able to:
- View a list of all tickets.
- Cannot create a new ticket.
- View the replies to any ticket.
- Add a reply to any ticket.
- Close any ticket.
- Perform the above tasks via the url www.example.com/admin/support
In other words, a User and Administrator can perform very similar, but different functionality. What are ways that I can design this system to reduce the amount of copying and pasting that must be done?
So far, I have came up with two possibilities.
Create two sets of Routes with two Controllers - one for the user and one for the admin. Copy and paste most of the logic between the Controllers, but changing a few variables so that users can only see his own tickets. Both Controllers share the same Views and Model. Add in an additional check in the Views so that the admin do not see a button to create a new ticket.
The down side of this is that I have to put logic in the Views in order to hide certain things from the admin, and other things from the user. I am also copying and pasting code between controllers.
Create two sets of Routes but use the same Controller. Use if statements in the Controller to show different Views depending on whether it is a User or an Administrator.
However, now I am copying and pasting code between views. Having two different set of logic in the same Controller may be a bit confusing as well.
Is there a better way to go about this?