Controller Logic

PHOTO EMBED

Fri Oct 28 2022 12:53:53 GMT+0000 (Coordinated Universal Time)

Saved by @dustbuster #php #controller #laravel

// show
return Responder::respondValid(
    [
        'Model' => Model::with($relationships)->find($consultTopicId)
    ]
);

// index
return Responder::respondValid(
  	[
      	'MemberProviderConsults' => ConsultLogResource::collection(
        	MemberProviderConsult::with(
            	$this->relations
            )->where('columns', $filter)->orderBy('id', 'desc')->get()
      )
  ]
);

// Store
 $models = Model::create(
    [
        'name' => $request->input('name')
        'description' => $request->input('description', null)
    ]
);

$model->BelongsToManyRelation()->sync($request->input('relatedModelIds'));

return Responder::respondValid(
    [
        'model' => $model
    ]
);

// Update
$model = Model::find($modelId);

if ($request->input('name')) {
    $model->update(
        [
            'name' => $request->input('name')
            'description' => $request->input('description', null)
        ]
    );
}
$model->belongsToManyRelation()->sync($request->input('relatedModelIds'));
$model->questions()->sync($request->input('otherRelatedModelIds'));

$this->updateRequiredQuestions($request, $model->id);

return Responder::respondValid(
    [
        'model' => $model->refresh()->load($this->relations)
    ]
);
content_copyCOPY

Just some well worn controller logic

controller-logic