añadir nuevas funcionalidades
This commit is contained in:
@@ -17,12 +17,16 @@ class ProjectController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$projects = Project::withCount('documents')
|
||||
->whereHas('users', function($query) {
|
||||
$projects = auth()->user()->hasRole('admin')
|
||||
? Project::get() // Todos los proyectos para admin
|
||||
: auth()->user()->projects()->latest()->get(); // Solo proyectos asignados
|
||||
|
||||
/*
|
||||
$projects = Project::whereHas('users', function($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
})
|
||||
->filter(['search' => request('search')])
|
||||
->paginate(9);
|
||||
->paginate(9);*/
|
||||
|
||||
return view('projects.index', compact('projects'));
|
||||
}
|
||||
@@ -47,24 +51,24 @@ class ProjectController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'required|string',
|
||||
'status' => 'required|in:active,inactive',
|
||||
'team' => 'sometimes|array',
|
||||
'team.*' => 'exists:users,id',
|
||||
'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')),
|
||||
//'icon' => 'nullable|in:'.implode(',', config('project.icons')),
|
||||
'start_date' => 'nullable|date',
|
||||
'deadline' => 'nullable|date|after:start_date',
|
||||
'categories' => 'array|exists:categories,id',
|
||||
'categories' => 'nullable|array|exists:categories,id',
|
||||
//'categories' => 'required|array',
|
||||
'categories.*' => 'exists:categories,id',
|
||||
'documents.*' => 'file|max:5120|mimes:pdf,docx,xlsx,jpg,png'
|
||||
//'categories.*' => 'exists:categories,id',
|
||||
//'documents.*' => 'file|max:5120|mimes:pdf,docx,xlsx,jpg,png'
|
||||
]);
|
||||
|
||||
|
||||
@@ -89,6 +93,7 @@ class ProjectController extends Controller
|
||||
}
|
||||
|
||||
// Manejar documentos adjuntos
|
||||
/*
|
||||
if($request->hasFile('documents')) {
|
||||
foreach ($request->file('documents') as $file) {
|
||||
$project->documents()->create([
|
||||
@@ -96,14 +101,12 @@ class ProjectController extends Controller
|
||||
'original_name' => $file->getClientOriginalName()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return redirect()->route('projects.show', $project)
|
||||
->with('success', 'Proyecto creado exitosamente');
|
||||
return redirect()->route('projects.show', $project)->with('success', 'Proyecto creado exitosamente');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return back()->withInput()
|
||||
->with('error', 'Error al crear el proyecto: ' . $e->getMessage());
|
||||
return back()->withInput()->with('error', 'Error al crear el proyecto: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +115,7 @@ class ProjectController extends Controller
|
||||
*/
|
||||
public function show(Project $project)
|
||||
{
|
||||
$this->authorize('view', $project); // Si usas políticas
|
||||
//$this->authorize('view', $project); // Si usas políticas
|
||||
$project->load(['categories', 'documents']);
|
||||
|
||||
return view('projects.show', [
|
||||
|
||||
Reference in New Issue
Block a user