I am trying to split some code and let model handle all database stuff, such as create, retrieve etc.
At the moment all of that code was in the controller and I quickly realized that code is very messy so instead I wanted to do something like this:
public function incompletedEntity(EntityRequestPartial $request)
{
$partial_entity = EntityTrash::saveEntity();
}
And my model:
public static function saveEntity(Request $request)
{
$entity = new EntityTrash();
$entity->lat = $request->input('lat');
$entity->lng = $request->input('lng');
$entity->slug = $request->input('name');
$user_id = Auth::id();
$entity->name = $request->input('name');
$entity->type = $request->input('type');
$entity->email = $request->input('email');
$entity->tags = $request->input('tags');
$entity->slug = $user_id;
$entity->building_name = $request->input('building_name');
$entity->address = $request->input('address');
$entity->town = $request->input('town');
$entity->postcode = $request->input('postcode');
$entity->telephone = $request->input('telephone');
$entity->save();
}
However, I cannot call that function because I am not passing an argument from the controller, what is the right approach for this? Should I do $request->input in controller and assign it to an array maybe? and deal with it in the controller?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire