Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

316
Vistas
Laravel: passing parameters to function?

I am trying to pass two parameters to a function in whereHas with Laravel because otherwhys it wont be able to use the $businessid but it's throwing an error, can anyone help?

Error:

FatalThrowableError in HomeController.php line 16: Type error: Too few arguments to function App\Http\Controllers\Business\User\HomeController::App\Http\Controllers\Business\User{closure}(), 1 passed in C:\web\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php on line 938 and exactly 2 expected


Code:

<?php

namespace App\Http\Controllers\Business\User;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use App\Database\Frontend\Roleplay\Business\Businesses;
use App\Database\Frontend\User\Player;

class HomeController extends Controller
{
    public function getView(Request $request, $businessid)
    {
        $workerCount = Player::whereHas("roleplay", function($q2, $businessid) {
            $q2->where('business_id', $businessid);
        })->count();

        $workersWorkingCount = Player::where('currently_working', '1')->whereHas("roleplay", function($q2, $businessid) {
            $q2->where('business_id', $businessid);
        })->count();

        $workersOnlineCount = Player::where('online', '1')->whereHas("roleplay", function($q2, $businessid) {
            $q2->where('business_id', $businessid);
        })->count();

        $workersOfflineCount = Player::where('online', '0')->whereHas("roleplay", function($q2, $businessid) {
            $q2->where('business_id', $businessid);
        })->count();

        return view('business.home', compact(
            'workerCount',
            'workersWorkingCount',
            'workersOnlineCount',
            'workersOfflineCount'));
    }
}
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This is how you can pass variable(s) to the function..

        $workerCount = Player::whereHas("roleplay", function($q2) use ($businessid) {
            $q2->where('business_id', $businessid);
        })->count();
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda