mejoras
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
@@ -37,8 +38,9 @@ class ProjectController extends Controller
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('create projects');
|
||||
|
||||
$project = new Project();
|
||||
return view('projects.create', [
|
||||
'project' => $project,
|
||||
'categories' => Category::orderBy('name')->get(),
|
||||
'users' => User::where('id', '!=', auth()->id())->get(),
|
||||
]);
|
||||
@@ -50,25 +52,22 @@ class ProjectController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'reference' => 'required|string|max:255',
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'status' => 'required|in:Activo,Inactivo',
|
||||
//'team' => 'sometimes|array',
|
||||
//'team.*' => 'exists:users,id',
|
||||
'project_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'address' => 'nullable|string|max:255',
|
||||
'province' => 'nullable|string|max:100',
|
||||
//'country' => 'nullable|string|size:2',
|
||||
'country' => 'nullable|string|size:2',
|
||||
'postal_code' => 'nullable|string|max:10',
|
||||
'latitude' => 'required|numeric|between:-90,90',
|
||||
'longitude' => 'required|numeric|between:-180,180',
|
||||
//'icon' => 'nullable|in:'.implode(',', config('project.icons')),
|
||||
'start_date' => 'nullable|date',
|
||||
'deadline' => 'nullable|date|after:start_date',
|
||||
'categories' => 'nullable|array|exists:categories,id',
|
||||
//'categories' => 'required|array',
|
||||
//'categories.*' => 'exists:categories,id',
|
||||
//'documents.*' => 'file|max:5120|mimes:pdf,docx,xlsx,jpg,png'
|
||||
'project_image_path' => 'nullable|string',
|
||||
]);
|
||||
|
||||
|
||||
@@ -79,11 +78,14 @@ class ProjectController extends Controller
|
||||
]);
|
||||
|
||||
// Manejar la imagen
|
||||
if ($request->hasFile('project_image')) {
|
||||
$path = $request->file('project_image')->store('project-images', 'public');
|
||||
$validated['project_image_path'] = $path; // Usar el nombre correcto de columna
|
||||
if ($request->has('project_image_path') && $request->project_image_path) {
|
||||
$tempPath = $request->project_image_path;
|
||||
$newPath = 'images/projects/' . basename($tempPath);
|
||||
|
||||
Storage::move($tempPath, $newPath); // Mover el archivo
|
||||
$validated['project_image_path'] = $newPath; // Actualizar path
|
||||
}
|
||||
|
||||
|
||||
// Crear el proyecto con todos los datos validados
|
||||
$project = Project::create($validated);
|
||||
|
||||
@@ -92,17 +94,6 @@ class ProjectController extends Controller
|
||||
$project->categories()->sync($request->categories);
|
||||
}
|
||||
|
||||
// Manejar documentos adjuntos
|
||||
/*
|
||||
if($request->hasFile('documents')) {
|
||||
foreach ($request->file('documents') as $file) {
|
||||
$project->documents()->create([
|
||||
'file_path' => $file->store('project-documents', 'public'),
|
||||
'original_name' => $file->getClientOriginalName()
|
||||
]);
|
||||
}
|
||||
}*/
|
||||
|
||||
return redirect()->route('projects.show', $project)->with('success', 'Proyecto creado exitosamente');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -110,6 +101,19 @@ class ProjectController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Project $project)
|
||||
{
|
||||
$this->authorize('update', $project);
|
||||
return view('projects.create', [
|
||||
'project' => $project,
|
||||
'categories' => Category::orderBy('name')->get(),
|
||||
'users' => User::where('id', '!=', auth()->id())->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
@@ -125,14 +129,6 @@ class ProjectController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Project $project)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user