|
@@ -76,9 +76,40 @@ class ProjectController extends Controller
|
|
|
/**
|
|
|
* Update the specified resource in storage.
|
|
|
*/
|
|
|
- public function update(Request $request, string $id)
|
|
|
+ public function update(CreateOrUpdateRequest $request, string $id)
|
|
|
{
|
|
|
- //
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->fill([
|
|
|
+ ...$request->all(),
|
|
|
+ 'whitelist' => $request->whitelist ? sprintf(",%s", implode(',', $request->whitelist)) : null,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ if ($request->has("assets")) {
|
|
|
+ ProjectAsset::where('project_id', $project->id)->delete();
|
|
|
+
|
|
|
+ foreach ($request->get("assets", []) as $assetId) {
|
|
|
+ ProjectAsset::create([
|
|
|
+ 'project_id' => $project->id,
|
|
|
+ 'asset_id' => $assetId,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($request->has("plans")) {
|
|
|
+ ProjectPlan::where('project_id', $project->id)->delete();
|
|
|
+
|
|
|
+ foreach ($request->get("plans", []) as $planId) {
|
|
|
+ ProjectPlan::create([
|
|
|
+ 'project_id' => $project->id,
|
|
|
+ 'plan_id' => $planId,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,6 +117,10 @@ class ProjectController extends Controller
|
|
|
*/
|
|
|
public function destroy(string $id)
|
|
|
{
|
|
|
- //
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->delete();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
}
|
|
|
}
|