Good day to All,
I am just curious as to how you peeps are separating the controller workload.
Lets say I have the following controllers:
- ItemController
- ItemImageController
So it should be clear that an item may have multiple images.
Now when storing the data for relevant models:
How would you handle the upload / persisting of the Image record?
Would you do your insert to db from the ItemController@store method?
If NOT - how do you do this as usually you would have the Item and Image fields on the same view and form?
Cause in my situation I am sitting with the following form:
{!! Form::open(array('route' => 'items.store', 'method' => 'POST', "files" => true)) !!}
<div class="row form-group">
<div class="col-md-6">
{!! Form::label('name', 'Item:') !!}
{!! Form::text('name', "", ["class" => "form-control"]) !!}
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description', "", ["class" => "form-control]) !!}
{!! Form::label('photos[]', 'Photos:') !!}
{!! Form::file('photos[]', ["class" => "form-control", "multiple"]) !!}
</div>
</div>
<div class="row form-group" >
<div class="col-md-6">
{!! Form::submit("Save", ["class" => "btn btn-md btn-primary"]) !!}
</div>
</div>
{!! Form::close() !!}
So you can see the form will be posted to: "items.store" ake ItemController@store.
How will I store the photos from that controller? Should the ItemImageController@store method not be responsible for that and how do you reference ItemImageController@store from inside ItemController@store?
I really would like to keep controllers clean and also follow good practices.
Thanks :)