Fix: Correcciones panel admin y API frontend

## Panel de Administración

### FormBuilder personalizado (Laravel 11)
- Creado app/Support/FormBuilder.php como reemplazo de laravelcollective/html
- Creado app/Support/Facades/Form.php para el facade
- Registrado en AppServiceProvider y config/app.php
- Soporta: text, email, password, file, textarea, select, checkbox, radio, etc.
- Manejo de valores null en todos los parámetros

### Configuración de sesión
- Cambiado same_site de "none" a "lax" para compatibilidad HTTP
- Corrige error 419 Page Expired en login

### Status CRUD
- Agregado campo en_name al formulario (español/inglés)
- Actualizado StatusController create/update para manejar en_name

### Dependencias
- Instalado spatie/laravel-google-cloud-storage para driver GCS

## API Frontend

### Validaciones de perfil de proveedor
Agregadas validaciones en endpoints que requieren perfil de proveedor:

- SupplierController::getpostulation - Retorna error 400 si no hay perfil
- SupplierController::getcontractedpostulation - Retorna error 400 si no hay perfil
- PostulationController::postulate - Retorna error 400 si no hay perfil
- PostulationController::getfinishedpostulations - Retorna error 400 si no hay perfil
- ContractController::startcontract - Retorna error 400 si no hay perfil

### Null safety en contratos
- ContractController::getcurrentcontracts - Manejo seguro de supplier/category null
- ContractController::getfinishedcontracts - Manejo seguro de supplier/category/status null

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-18 23:16:34 +00:00
parent 46469deaa8
commit 5e3b203f84
12 changed files with 469 additions and 13 deletions

View File

@@ -639,12 +639,12 @@ class ContractController extends Controller
$day_limit = Carbon::parse($ccontract->created_at); $day_limit = Carbon::parse($ccontract->created_at);
$currentcontractinfo = array( $currentcontractinfo = array(
'id' => $ccontract->id, 'id' => $ccontract->id,
'phone' => $supplier->user->phone, 'phone' => $supplier ? ($supplier->user ? $supplier->user->phone : null) : null,
'category' => $category->name, 'category' => $category ? $category->name : null,
'en_category' => $category->en_name, 'en_category' => $category ? $category->en_name : null,
'address' => $ccontract->address, 'address' => $ccontract->address,
'date' => $ccontract->appointment, 'date' => $ccontract->appointment,
'supplier' => $supplier->company_name, 'supplier' => $supplier ? $supplier->company_name : 'Proveedor no disponible',
'status' => $ccontract->status_id, 'status' => $ccontract->status_id,
'amount' => $ccontract->amount, 'amount' => $ccontract->amount,
'code' => $ccontract->code, 'code' => $ccontract->code,
@@ -778,6 +778,14 @@ class ContractController extends Controller
$user = Auth::user(); $user = Auth::user();
$supplier = $user->suppliers; $supplier = $user->suppliers;
if (!$supplier) {
return response()->json([
'success' => false,
'message' => 'No tienes un perfil de proveedor registrado'
], 400);
}
$ccontract = CurrentContracts::where('code', $request->contract_pin)->where('supplier_id', $supplier->id)->first(); $ccontract = CurrentContracts::where('code', $request->contract_pin)->where('supplier_id', $supplier->id)->first();
if($ccontract) { if($ccontract) {
@@ -969,16 +977,16 @@ class ContractController extends Controller
$day_limit = Carbon::parse($fcontract->created_at); $day_limit = Carbon::parse($fcontract->created_at);
$finishedcontractinfo = array( $finishedcontractinfo = array(
'id' => $fcontract->id, 'id' => $fcontract->id,
'category' => $category->name, 'category' => $category ? $category->name : null,
'en_category' => $category->en_name, 'en_category' => $category ? $category->en_name : null,
'address' => $fcontract->address, 'address' => $fcontract->address,
'date' => $fcontract->appointment, 'date' => $fcontract->appointment,
'date_difference' => $time_limit->diff(Carbon::now(), false)->days, 'date_difference' => $time_limit->diff(Carbon::now(), false)->days,
'supplier' => $supplier->company_name, 'supplier' => $supplier ? $supplier->company_name : 'Proveedor no disponible',
'amount' => $fcontract->amount, 'amount' => $fcontract->amount,
'scored' => $fcontract->scored_at, 'scored' => $fcontract->scored_at,
'parent' => $fcontract->parent_contract_id, 'parent' => $fcontract->parent_contract_id,
'status' => $fcontract->status->name 'status' => $fcontract->status ? $fcontract->status->name : null
); );
$finishedcontracts[] = $finishedcontractinfo; $finishedcontracts[] = $finishedcontractinfo;
} }

View File

@@ -218,6 +218,13 @@ class PostulationController extends Controller
$time_limit = (9900 - Carbon::now()->diffInMinutes($time_created)); $time_limit = (9900 - Carbon::now()->diffInMinutes($time_created));
$supplier = Suppliers::where('user_id', $user->id)->first(); $supplier = Suppliers::where('user_id', $user->id)->first();
if (!$supplier) {
return response()->json([
'success' => false,
'message' => 'No tienes un perfil de proveedor registrado'
], 400);
}
if ($time_limit > 0) { if ($time_limit > 0) {
if (in_array($postulation->category_id, $supplier->categories->pluck('id')->toArray())) { if (in_array($postulation->category_id, $supplier->categories->pluck('id')->toArray())) {
/*if($supplier->membership == 1) { /*if($supplier->membership == 1) {
@@ -282,6 +289,14 @@ class PostulationController extends Controller
public function getfinishedpostulations(Request $request) { public function getfinishedpostulations(Request $request) {
$user = Auth::user(); $user = Auth::user();
if (!$user->suppliers) {
return response()->json([
'success' => false,
'message' => 'No tienes un perfil de proveedor registrado'
], 400);
}
$postulations = FinishedContracts::where('supplier_id', $user->suppliers->id)->orderBy('created_at', 'DESC')->get(); $postulations = FinishedContracts::where('supplier_id', $user->suppliers->id)->orderBy('created_at', 'DESC')->get();
$finishedpostulations = array(); $finishedpostulations = array();

View File

@@ -53,10 +53,12 @@ class StatusController extends Controller
$rules = [ $rules = [
'name' => 'required|string', 'name' => 'required|string',
'en_name' => 'required|string',
]; ];
$messages = [ $messages = [
'name.required' => 'Se requiere el nombre del status', 'name.required' => 'Se requiere el nombre del status',
'en_name.required' => 'Se requiere el nombre del status en inglés',
]; ];
$validator = Validator::make($request->all(), $rules, $messages); $validator = Validator::make($request->all(), $rules, $messages);
@@ -66,6 +68,7 @@ class StatusController extends Controller
$status = new Status(); $status = new Status();
$status->name = strip_tags($request->name); $status->name = strip_tags($request->name);
$status->en_name = strip_tags($request->en_name);
$status->save(); $status->save();
return redirect('status'); return redirect('status');
@@ -119,10 +122,12 @@ class StatusController extends Controller
$rules = [ $rules = [
'name' => 'required|string', 'name' => 'required|string',
'en_name' => 'required|string',
]; ];
$messages = [ $messages = [
'name.required' => 'Se requiere el nombre del status', 'name.required' => 'Se requiere el nombre del status',
'en_name.required' => 'Se requiere el nombre del status en inglés',
]; ];
$validator = Validator::make($request->all(), $rules, $messages); $validator = Validator::make($request->all(), $rules, $messages);
@@ -132,6 +137,7 @@ class StatusController extends Controller
$status = Status::find($id); $status = Status::find($id);
$status->name = strip_tags($request->name); $status->name = strip_tags($request->name);
$status->en_name = strip_tags($request->en_name);
$status->save(); $status->save();
return redirect('status'); return redirect('status');

View File

@@ -1211,6 +1211,14 @@ class SupplierController extends Controller
$user = Auth::user(); $user = Auth::user();
$supplier = Suppliers::where('user_id', $user->id)->first(); $supplier = Suppliers::where('user_id', $user->id)->first();
if (!$supplier) {
return response()->json([
'success' => false,
'message' => 'No tienes un perfil de proveedor registrado'
], 400);
}
$distance = 0.5; $distance = 0.5;
$postulations = Postulations::distance('location', $supplier->location, $distance)->orderBy('created_at', 'DESC')->get(); $postulations = Postulations::distance('location', $supplier->location, $distance)->orderBy('created_at', 'DESC')->get();
@@ -1246,6 +1254,14 @@ class SupplierController extends Controller
$user = Auth::user(); $user = Auth::user();
$supplier = Suppliers::where('user_id', $user->id)->first(); $supplier = Suppliers::where('user_id', $user->id)->first();
if (!$supplier) {
return response()->json([
'success' => false,
'message' => 'No tienes un perfil de proveedor registrado'
], 400);
}
$contracts = CurrentContracts::where('supplier_id', $supplier->id)->orderBy('created_at', 'DESC')->get(); $contracts = CurrentContracts::where('supplier_id', $supplier->id)->orderBy('created_at', 'DESC')->get();
$contractsinfo = array(); $contractsinfo = array();

View File

@@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use App\Services\SocialUserResolver; use App\Services\SocialUserResolver;
use App\Support\FormBuilder;
use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface; use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -25,7 +26,9 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function register() public function register()
{ {
// $this->app->singleton('form', function ($app) {
return new FormBuilder();
});
} }
/** /**

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Support\Facades;
use Illuminate\Support\Facades\Facade;
class Form extends Facade
{
protected static function getFacadeAccessor()
{
return 'form';
}
}

265
app/Support/FormBuilder.php Normal file
View File

@@ -0,0 +1,265 @@
<?php
namespace App\Support;
use Illuminate\Support\HtmlString;
class FormBuilder
{
protected $model;
public function model($model, $options = [])
{
$this->model = $model;
return $this->open($options ?? []);
}
public function open($options = [])
{
$options = $options ?? [];
$method = strtoupper($options['method'] ?? 'POST');
$action = $options['url'] ?? ($options['action'] ?? '');
$files = isset($options['files']) && $options['files'] ? ' enctype="multipart/form-data"' : '';
$class = isset($options['class']) ? ' class="' . e($options['class']) . '"' : '';
$id = isset($options['id']) ? ' id="' . e($options['id']) . '"' : '';
$html = '<form method="' . ($method === 'GET' ? 'GET' : 'POST') . '" action="' . e($action) . '"' . $files . $class . $id . '>';
$html .= csrf_field();
if (!in_array($method, ['GET', 'POST'])) {
$html .= method_field($method);
}
return new HtmlString($html);
}
public function close()
{
$this->model = null;
return new HtmlString('</form>');
}
public function token()
{
return csrf_field();
}
public function label($name, $value = null, $options = [], $escapeHtml = true)
{
$options = $options ?? [];
$value = $value ?? ucfirst(str_replace('_', ' ', $name));
$for = ' for="' . e($name) . '"';
$attributes = $this->attributes($options);
return new HtmlString('<label' . $for . $attributes . '>' . ($escapeHtml ? e($value) : $value) . '</label>');
}
public function text($name, $value = null, $options = [])
{
return $this->input('text', $name, $value, $options ?? []);
}
public function email($name, $value = null, $options = [])
{
return $this->input('email', $name, $value, $options ?? []);
}
public function password($name, $options = [])
{
return $this->input('password', $name, null, $options ?? []);
}
public function hidden($name, $value = null, $options = [])
{
return $this->input('hidden', $name, $value, $options ?? []);
}
public function number($name, $value = null, $options = [])
{
return $this->input('number', $name, $value, $options ?? []);
}
public function file($name, $options = [])
{
return $this->input('file', $name, null, $options ?? []);
}
public function textarea($name, $value = null, $options = [])
{
$options = $options ?? [];
$value = $this->getValueAttribute($name, $value);
$attributes = $this->attributes(array_merge(['name' => $name, 'id' => $name], $options));
return new HtmlString('<textarea' . $attributes . '>' . e($value ?? '') . '</textarea>');
}
public function select($name, $list = [], $selected = null, $options = [], $optionsAttributes = [], $optgroupsAttributes = [])
{
$options = $options ?? [];
$list = $list ?? [];
$selected = $this->getValueAttribute($name, $selected);
$attributes = $this->attributes(array_merge(['name' => $name, 'id' => $name], $options));
$html = '<select' . $attributes . '>';
foreach ($list as $key => $value) {
if (is_array($value)) {
$html .= '<optgroup label="' . e($key) . '">';
foreach ($value as $optKey => $optValue) {
$html .= $this->option($optKey, $optValue, $selected);
}
$html .= '</optgroup>';
} else {
$html .= $this->option($key, $value, $selected);
}
}
$html .= '</select>';
return new HtmlString($html);
}
protected function option($key, $value, $selected)
{
$isSelected = $this->isSelected($key, $selected) ? ' selected' : '';
return '<option value="' . e($key) . '"' . $isSelected . '>' . e($value) . '</option>';
}
protected function isSelected($key, $selected)
{
if (is_array($selected)) {
return in_array($key, $selected);
}
return (string) $key === (string) $selected;
}
public function checkbox($name, $value = 1, $checked = null, $options = [])
{
$options = $options ?? [];
$checked = $this->getCheckedState($name, $value, $checked) ? ' checked' : '';
$attributes = $this->attributes(array_merge([
'name' => $name,
'id' => $options['id'] ?? $name,
'value' => $value,
'type' => 'checkbox'
], $options));
return new HtmlString('<input' . $attributes . $checked . '>');
}
public function radio($name, $value = null, $checked = null, $options = [])
{
$options = $options ?? [];
$checked = $this->getCheckedState($name, $value, $checked) ? ' checked' : '';
$attributes = $this->attributes(array_merge([
'name' => $name,
'id' => $options['id'] ?? $name . '_' . $value,
'value' => $value,
'type' => 'radio'
], $options));
return new HtmlString('<input' . $attributes . $checked . '>');
}
public function submit($value = null, $options = [])
{
return $this->input('submit', null, $value, $options ?? []);
}
public function button($value = null, $options = [])
{
$options = $options ?? [];
$attributes = $this->attributes(array_merge(['type' => 'button'], $options));
return new HtmlString('<button' . $attributes . '>' . e($value ?? '') . '</button>');
}
public function input($type, $name, $value = null, $options = [])
{
$options = $options ?? [];
if ($type !== 'password' && $type !== 'file') {
$value = $this->getValueAttribute($name, $value);
}
$attributes = $this->attributes(array_merge([
'type' => $type,
'name' => $name,
'id' => $options['id'] ?? $name,
'value' => $value
], $options));
return new HtmlString('<input' . $attributes . '>');
}
public function date($name, $value = null, $options = [])
{
return $this->input('date', $name, $value, $options ?? []);
}
public function time($name, $value = null, $options = [])
{
return $this->input('time', $name, $value, $options ?? []);
}
public function datetime($name, $value = null, $options = [])
{
return $this->input('datetime-local', $name, $value, $options ?? []);
}
protected function getValueAttribute($name, $value = null)
{
if (is_null($name)) {
return $value;
}
$old = old($name);
if (!is_null($old)) {
return $old;
}
if (!is_null($value)) {
return $value;
}
if ($this->model && isset($this->model->{$name})) {
return $this->model->{$name};
}
return null;
}
protected function getCheckedState($name, $value, $checked)
{
$old = old($name);
if (!is_null($old)) {
return $old == $value;
}
if (!is_null($checked)) {
return $checked;
}
if ($this->model && isset($this->model->{$name})) {
return $this->model->{$name} == $value;
}
return false;
}
protected function attributes($attributes)
{
$attributes = $attributes ?? [];
$html = '';
foreach ($attributes as $key => $value) {
if (is_null($value)) {
continue;
}
if (is_numeric($key)) {
$html .= ' ' . $value;
} else {
$html .= ' ' . $key . '="' . e($value) . '"';
}
}
return $html;
}
}

View File

@@ -20,11 +20,12 @@
"laravel/socialite": "^5.10", "laravel/socialite": "^5.10",
"laravel/tinker": "^2.9", "laravel/tinker": "^2.9",
"laravel/ui": "^4.6", "laravel/ui": "^4.6",
"spatie/laravel-html": "^3.0",
"lcobucci/jwt": "^5.0", "lcobucci/jwt": "^5.0",
"mercadopago/dx-php": "^3.5", "mercadopago/dx-php": "^3.5",
"missael-anda/laravel-whatsapp": "^0.8.6", "missael-anda/laravel-whatsapp": "^0.8.6",
"openpay/sdk": "^2.0", "openpay/sdk": "^2.0",
"spatie/laravel-google-cloud-storage": "^2.3",
"spatie/laravel-html": "^3.0",
"tarfin-labs/laravel-spatial": "*", "tarfin-labs/laravel-spatial": "*",
"timehunter/laravel-google-recaptcha-v3": "^2.4" "timehunter/laravel-google-recaptcha-v3": "^2.4"
}, },

123
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bff602eb6c826efc24c4833d959d4c90", "content-hash": "5e417628f1993b1a32e8bdd7a16566de",
"packages": [ "packages": [
{ {
"name": "berkayk/onesignal-laravel", "name": "berkayk/onesignal-laravel",
@@ -3014,6 +3014,54 @@
}, },
"time": "2025-11-10T17:13:11+00:00" "time": "2025-11-10T17:13:11+00:00"
}, },
{
"name": "league/flysystem-google-cloud-storage",
"version": "3.30.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem-google-cloud-storage.git",
"reference": "2d36f1a050fe70bf21d8aa75275963f9ca2e16ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem-google-cloud-storage/zipball/2d36f1a050fe70bf21d8aa75275963f9ca2e16ea",
"reference": "2d36f1a050fe70bf21d8aa75275963f9ca2e16ea",
"shasum": ""
},
"require": {
"google/cloud-storage": "^1.23",
"league/flysystem": "^3.10.0",
"league/mime-type-detection": "^1.0.0",
"php": "^8.0.2"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\Flysystem\\GoogleCloudStorage\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frankdejonge.nl"
}
],
"description": "Google Cloud Storage adapter for Flysystem.",
"keywords": [
"Flysystem",
"filesystem",
"gcs",
"google cloud storage"
],
"support": {
"source": "https://github.com/thephpleague/flysystem-google-cloud-storage/tree/3.30.1"
},
"time": "2025-10-20T15:27:33+00:00"
},
{ {
"name": "league/flysystem-local", "name": "league/flysystem-local",
"version": "3.30.2", "version": "3.30.2",
@@ -5430,6 +5478,79 @@
], ],
"time": "2025-12-02T15:19:04+00:00" "time": "2025-12-02T15:19:04+00:00"
}, },
{
"name": "spatie/laravel-google-cloud-storage",
"version": "2.3.4",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-google-cloud-storage.git",
"reference": "10c91e6dcaebf83eba9f21b8107267595bb40d2a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-google-cloud-storage/zipball/10c91e6dcaebf83eba9f21b8107267595bb40d2a",
"reference": "10c91e6dcaebf83eba9f21b8107267595bb40d2a",
"shasum": ""
},
"require": {
"illuminate/contracts": "^10.0|^11.0|^12.0",
"illuminate/filesystem": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"league/flysystem-google-cloud-storage": "^3.0.15",
"php": "^8.0"
},
"require-dev": {
"nunomaduro/collision": "^7.0|^8.0",
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpunit/phpunit": "^10.0|^11.0|^12.0",
"spatie/laravel-ray": "^1.29"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"GoogleCloudStorage": "Spatie\\GoogleCloudStorage\\GoogleCloudStorageFacade"
},
"providers": [
"Spatie\\GoogleCloudStorage\\GoogleCloudStorageServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Spatie\\GoogleCloudStorage\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alex Vanderbist",
"email": "alex@spatie.be",
"role": "Developer"
}
],
"description": "Google Cloud Storage filesystem driver for Laravel",
"homepage": "https://github.com/spatie/laravel-google-cloud-storage",
"keywords": [
"laravel",
"laravel-google-cloud-storage",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-google-cloud-storage/issues",
"source": "https://github.com/spatie/laravel-google-cloud-storage/tree/2.3.4"
},
"funding": [
{
"url": "https://github.com/spatie",
"type": "github"
}
],
"time": "2025-03-13T09:56:26+00:00"
},
{ {
"name": "spatie/laravel-html", "name": "spatie/laravel-html",
"version": "3.12.3", "version": "3.12.3",

View File

@@ -215,6 +215,7 @@ return [
'Eloquent' => Illuminate\Database\Eloquent\Model::class, 'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class, 'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class, 'File' => Illuminate\Support\Facades\File::class,
'Form' => App\Support\Facades\Form::class,
'Gate' => Illuminate\Support\Facades\Gate::class, 'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class, 'Hash' => Illuminate\Support\Facades\Hash::class,
'Image' => Intervention\Image\Laravel\Facades\Image::class, 'Image' => Intervention\Image\Laravel\Facades\Image::class,

View File

@@ -194,6 +194,6 @@ return [
| |
*/ */
'same_site' => "none", 'same_site' => env('SESSION_SAME_SITE', 'lax'),
]; ];

View File

@@ -11,12 +11,19 @@
{!! Form::open(['id'=>'frm']) !!} {!! Form::open(['id'=>'frm']) !!}
@endif @endif
<div class="form-group row required"> <div class="form-group row required">
{!! Form::label("name","Status",["class"=>"col-form-label col-md-3 col-lg-2"]) !!} {!! Form::label("name","Status (Español)",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
<div class="col-md-8"> <div class="col-md-8">
{!! Form::text("name",null,["class"=>"form-control".($errors->has('name')?" is-invalid":""),"autofocus",'placeholder'=>'Nombre del Status']) !!} {!! Form::text("name",null,["class"=>"form-control".($errors->has('name')?" is-invalid":""),"autofocus",'placeholder'=>'Nombre del Status']) !!}
<span id="error-name" class="invalid-feedback"></span> <span id="error-name" class="invalid-feedback"></span>
</div> </div>
</div> </div>
<div class="form-group row required">
{!! Form::label("en_name","Status (English)",["class"=>"col-form-label col-md-3 col-lg-2"]) !!}
<div class="col-md-8">
{!! Form::text("en_name",null,["class"=>"form-control".($errors->has('en_name')?" is-invalid":""),'placeholder'=>'Status Name']) !!}
<span id="error-en_name" class="invalid-feedback"></span>
</div>
</div>
@if ($errors->any()) @if ($errors->any())
<div class="alert alert-danger"> <div class="alert alert-danger">
<ul> <ul>