Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

489
Views
laravel PHP Error fatal: no se puede volver a declarar para la función

tengo la siguiente función:

 function get_user_browser() { $u_agent = $_SERVER['HTTP_USER_AGENT']; $ub = 'unknown'; if (preg_match('/Trident\/7.0; rv:11.0/', $u_agent)) { $ub = "ie ie-11"; } elseif(preg_match('/MSIE/i', $u_agent)) { $ub = "ie"; } elseif(preg_match('/Chrome/i', $u_agent)) { $ub = "chrome"; } elseif(preg_match('/Firefox/i', $u_agent)) { $ub = "firefox"; } elseif(preg_match('/Safari/i', $u_agent)) { $ub = "safari"; } elseif(preg_match('/Opera/i', $u_agent)) { $ub = "opera"; } return 'browser-'.$ub; }

Tengo esta función declarada en dos hojas y obtuve este error:

Error fatal de FPHP: no se puede volver a declarar get_user_browser() (anteriormente declarado en /home/storage/framework/views/0800146a0e35b205e9a66bb2f00ffb2f:7) en /home/storage/framework/views/0800146a0e35b205e9a66bb2f00ffb2f en la línea 7

¿Cómo puedo arreglarlo?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Aquí un truco simple inteligente

agregue un archivo llamado helpers.php en la carpeta de su aplicación

copia la función que escribiste dentro de ese archivo

agregue a composer.json en "carga automática" el bloque:

 "files": [ "app/helpers.php" ]

luego ejecute una actualización del compositor y obtendrá la función disponible en todo su código base

En este archivo, puede agregar cualquier función de ayuda que desee y, como ya se ha dicho, siempre debe evitar escribir código php dentro de las vistas.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!