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')); } }