title: MVC Controller(s) with RESTful API(s), multiple Models and shared Views
body: <p><strong>Foreword:</strong> The following text is of decent size, because I tried to maximize the value to other readers with similar, fundamental and conceptual questions.</p>
  
  <hr>
  
  <h2>Introduction</h2>
  
  <p>Currently I am developing an web-based event management tool, which uses the Laravel MVC framework to maintain a proper application structure and ease development.</p>
  
  <p>The goals targeted with the application are to</p>
  
  <ul>
  <li>provide a efficient way to create (respectively CRUD) events</li>
  <li>invite registered users to those events</li>
  <li>allow users to confirm their participation on previously created events</li>
  </ul>
  
  <p>Following the MVC-Pattern, I created</p>
  
  <ul>
  <li>a Model named <code>Event</code></li>
  <li>a <code>EventController</code></li>
  <li>multiple views
  <ul>
  <li>a static <code>event</code> view, displaying already existing events</li>
  <li>a form view for creation and editing named <code>eventForm</code></li>
  <li><code>eventIndex</code>,  a list of all events</li>
  </ul></li>
  </ul>
  
  <p>Up to this point, everything seemed to be relatively straight-forward, but I ran into design problems, when I tried to implement further functionality to allow users to confirm their participation on specific events.</p>
  
  <h3>Further Details</h3>
  
  <p>For further clarification, each <code>Event</code> has a number of attributes (some omitted):</p>
  
  <ul>
  <li>Title</li>
  <li>Description</li>
  <li>Multiple <code>EventDate</code>s, consisting out of this attributes:
  <ul>
  <li>Title</li>
  <li>A timespan (for example 09-20-2013 09:00 AM to 09-20-2013 05:00 PM)</li>
  </ul></li>
  </ul>
  
  <p>The aforementioned <code>EventDate</code> is also a model with an associated database table.</p>
  
  <p>Distinguished by the account a user is logged in with, I made a boolean variable <code>$admin</code> available to all views and controllers, which is used to alter the view <code>event</code> in the following way:</p>
  
  <ul>
  <li><strong>$admin = true:</strong> The view is a static page, showing the <code>Event</code>s attributes and <code>EventDate</code>s in a table</li>
  <li><strong>$admin = false:</strong> In addition, the view has a hidden form and buttons for each <code>EventDate</code> table row, allowing the users to confirm or decline their participation on each of the <code>EventDate</code>s</li>
  </ul>
  
  <p>Using a variable and <code>@if...@endif</code>-blocks to alter the view seems acceptable to me, as, despite of the hidden form, the differences between <em>User-Mode</em> and <em>Admin-Mode</em> are quite small.</p>
  
  <h2>The Problem</h2>
  
  <p>Now, the problem I am stuck at, is the following:</p>
  
  <p><em>Who is responsible for processing the POSTed data of the User-Mode hidden form?</em></p>
  
  <p>At first, here a few facts to the current development state:</p>
  
  <ul>
  <li><p>The <code>Event</code> controller currently offers the following functions:</p>
  
  <pre><code>/* CRUD functions */
  public function CreateEvent()
  public function ShowEvent($id)
  public function UpdateEvent($id)
  public function DeleteEvent($id)
  /* Form display helpers */
  public function NewEvent()
  public function EditEvent()
  </code></pre></li>
  <li>The <code>EventDate</code> Model is separate from the <code>Event</code> Model, as a <code>Event</code> has multiple <code>EventDate</code>s</li>
  <li>Confirmations are stored per user and <code>EventDate</code> in another separate table bound to the <code>EventDateConfirmation</code> model</li>
  </ul>
  
  <h2>Solution approaches</h2>
  
  <p>These are the options I have thougth of:</p>
  
  <ol>
  <li><p>The <code>EventController</code>, which must be extended with methods like <code>CreateEventDateConfirmation()</code> and so on, leading to multiple CRUD methods, which not even belong to this controller, as they are not directly regarded to the <code>Event</code> model and no change at all happens in the <code>events</code> table</p></li>
  <li><p>In a separate <code>EventDateConfirmationController</code>, only responsible for getting and setting the <code>EventDateConfirmation</code> model data, with two usage possibilities:</p>
  
  <ul>
  <li><p>Calling the <code>EventDateConfirmationControler</code> methods from the <code>EventController</code> by using the somewhat clunky</p>
  
  <pre><code>Controller::resolve(DEFAULT_BUNDLE,'EventDateConfirmationController')-&gt;CreateConfirmation($params);
  </code></pre></li>
  <li>Setting the route which responds to the hidden form POST-request to the corresponding <code>EventDateConfirmationController</code> action directly</li>
  </ul>
  
  <p>The first possibility has the disadvantage of calling an external controller in a unpleasant way which seems wrong to me, the second is not practicable when the form also contains data which belong directly to a event and therefore must be handled by the <code>Event</code> controller</p></li>
  <li><p><strong>??</strong></p></li>
  </ol>
  
  <p>In my opinion, neither #1 nor #2 are good solutions to the problem, as they seem to be hack-ish and do not fit very well in the MVC-pattern.</p>
  
  <p><strong>What alternatives are available, which would be a clean solution to this problem?</strong></p>
  
  <p>Thank you in advance!</p>