use App\Entities\Projects\Project;
use App\Entities\Projects\ProjectsRepository;
use App\Http\Controllers\Controller;
use App\Http\Requests\Projects\CreateRequest;
use App\Http\Requests\Projects\UpdateRequest;
use Illuminate\Http\Request;
class ProjectsController extends Controller
{
//
public function create()
{
$this->authorize('create', new Project());
$customers = $this->repo->getCustomersList();
return view('projects.create', compact('customers'));
}
public function store(CreateRequest $request)
{
$this->authorize('create', new Project());
$project = $this->repo->create($request->except('_token'));
flash(__('project.created'), 'success');
return redirect()->route('projects.show', $project);
}
public function show(Project $project)
{
$this->authorize('view', $project);
return view('projects.show', compact('project'));
}
public function edit(Project $project)
{
$this->authorize('update', $project);
$customers = $this->repo->getCustomersList();
return view('projects.edit', compact('project', 'customers'));
}
public function update(UpdateRequest $request, Project $project)
{
$this->authorize('update', $project);
$project = $this->repo->update($request->validated(), $project->id);
flash(__('project.updated'), 'success');
return redirect()->route('projects.edit', $project);
}
public function delete(Project $project)
{
$this->authorize('delete', $project);
return view('projects.delete', compact('project'));
}
public function destroy(Project $project)
{
$this->authorize('delete', $project);
if ($project->id == request('project_id')) {
$this->repo->delete($project->id);
flash(__('project.deleted'), 'success');
} else {
flash(__('project.undeleted'), 'danger');
}
return redirect()->route('projects.index');
}
//
}