152 lines
4.3 KiB
PHP
152 lines
4.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Http\Requests\Projects\StoreProjectRequest;
|
||
|
|
use App\Http\Requests\Projects\UpdateProjectRequest;
|
||
|
|
use App\Http\Requests\ValidateOtpRequest;
|
||
|
|
use App\Models\Project;
|
||
|
|
use App\Models\Server;
|
||
|
|
use Ramsey\Uuid\Uuid;
|
||
|
|
|
||
|
|
class ProjectController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
$projects = Project::orderBy('name')->get();
|
||
|
|
return view('projects.index', ['projects' => $projects]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create()
|
||
|
|
{
|
||
|
|
$dev_db_server = Server::where([
|
||
|
|
['env', 'DEV'],
|
||
|
|
['type', 'DB']
|
||
|
|
])->get();
|
||
|
|
$dev_web_server = Server::where([
|
||
|
|
['env', 'DEV'],
|
||
|
|
['type', 'WEB']
|
||
|
|
])->get();
|
||
|
|
$prod_db_server = Server::where([
|
||
|
|
['env', 'PROD'],
|
||
|
|
['type', 'DB']
|
||
|
|
])->get();
|
||
|
|
$prod_web_server = Server::where([
|
||
|
|
['env', 'PROD'],
|
||
|
|
['type', 'WEB']
|
||
|
|
])->get();
|
||
|
|
return view('projects.create', \compact(
|
||
|
|
'dev_db_server',
|
||
|
|
'dev_web_server',
|
||
|
|
'prod_db_server',
|
||
|
|
'prod_web_server'
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\Projects\StoreProjectRequest $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(StoreProjectRequest $request)
|
||
|
|
{
|
||
|
|
$project = new Project();
|
||
|
|
$project->uuid = Uuid::uuid4();
|
||
|
|
$this->makeChanges($request, $project);
|
||
|
|
return redirect()->route('projects.edit', ['uuid' => $project->uuid])->with('status', 'Sauvegardé !');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Project $project
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||
|
|
*/
|
||
|
|
public function edit(Project $project)
|
||
|
|
{
|
||
|
|
// phpcs:enable
|
||
|
|
$dev_db_server = Server::where([
|
||
|
|
['env', 'DEV'],
|
||
|
|
['type', 'DB']
|
||
|
|
])->get();
|
||
|
|
$dev_web_server = Server::where([
|
||
|
|
['env', 'DEV'],
|
||
|
|
['type', 'WEB']
|
||
|
|
])->get();
|
||
|
|
$prod_db_server = Server::where([
|
||
|
|
['env', 'PROD'],
|
||
|
|
['type', 'DB']
|
||
|
|
])->get();
|
||
|
|
$prod_web_server = Server::where([
|
||
|
|
['env', 'PROD'],
|
||
|
|
['type', 'WEB']
|
||
|
|
])->get();
|
||
|
|
return view('projects.edit', \compact(
|
||
|
|
'project',
|
||
|
|
'dev_db_server',
|
||
|
|
'dev_web_server',
|
||
|
|
'prod_db_server',
|
||
|
|
'prod_web_server'
|
||
|
|
));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\Projects\UpdateProjectRequest $request
|
||
|
|
* @param \App\Models\Project $project
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(UpdateProjectRequest $request, Project $project)
|
||
|
|
{
|
||
|
|
$project->fill($request->validated());
|
||
|
|
if ($project->saveOrFail()) {
|
||
|
|
return redirect()->route('projects.edit', compact('project'))
|
||
|
|
->with('success', trans('Projet mis à jour.'));
|
||
|
|
}
|
||
|
|
return \back();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Project $project
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy(Project $project)
|
||
|
|
{
|
||
|
|
return view('projects.delete', ['project' => $project]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\ValidateOtpRequest $request
|
||
|
|
* @param \App\Models\Project $project
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||
|
|
*/
|
||
|
|
public function destroySubmit(ValidateOtpRequest $request, Project $project)
|
||
|
|
{
|
||
|
|
// phpcs:enable
|
||
|
|
if ($project->deleteOrFail()) {
|
||
|
|
return redirect()->route('domain-names.index')
|
||
|
|
->with('warning', 'Nom de domaine supprimée !');
|
||
|
|
}
|
||
|
|
|
||
|
|
return back();
|
||
|
|
}
|
||
|
|
}
|