I am failing to receive all data which are inserted between two dates. for example start date: 2017-01-15 - 2018-05-15 : end date.
I want to get all wages of people who have worked for a specific project during that period of time, and my code is this so far:
$project = Project::find($project_id);
$projectStartDate = $project->start_date;
$projectEndDate = $project->end_date;
$usersOfProject = $project->users()->get();
foreach ($usersOfProject as $userOfProject){
$ids = $userOfProject->id;
$userWages = UserWage::where('user_id',$ids)->where('start_date','<=', $projectStartDate)->where('end_date','>=',$projectEndDate)->get();
foreach ($userWages as $userWage){
$wage= wage + $userWage->value;
return $wage;
}
}
when I dd($ids); it shows only 1 user that's working for the project, not all of them. (currently two working on it).
fillables for UserWages are these:
protected $fillable = [
'value', 'currency', 'user_id', 'start_date', 'end_date',
];
, Projects:
protected $fillable = [
'name', 'description', 'start_date', 'end_date', 'value', 'client_id','currency','',
];
, User:
protected $fillable = [
'email', 'password', 'first_name', 'last_name', 'status_id','mobile', 'role',
];
The purpose of all this is that I am trying to get the wage of every user who has worked for this project during the of project start and project end. Wages might change from month to month, and so the exchange rate of them (payment can be done in USD, Euro or Albanian Lek);
I am trying to get all wages of users who are part of the project, and calculate data, for each pay that they might have had. with the exchange rate of that month, exchange rate can be filled by the admin.
code for Exchange rate is this:
function exchangeRate($value, $currency){
$getCurrency = Exchange::whereDate('date','2017-11-30'); //This is just for test to calculate wages with exchange rate of november 30, will do with carbon to get last date of month.
$dollar = $getCurrency->dollar_lek;
$euro = $getCurrency->euro_lek;
if ($currency == 'ALL') {
$value = $value;
} elseif ($currency == 'USD') {
$value = $value * $dollar;
} else {
$value = $value * $euro;
}
}
fillables for Exchange rate are
protected $fillable =[
'euro_lek', 'dollar_lek', 'date',
];
dd($ids)the loop halts at the first iteration. That's why it show only one user. usedump($ids)instead.$usersOfProject = $project->users()->get();dd($userWage->value)I get nothing