У меня есть этот код в моем Laravel -5.8
Контроллере
public function edit($id)
{
if (! Gate::allows('appraisal_goal_edit')) {
return abort(401);
}
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$identities = DB::table('appraisal_identity')->select('id','appraisal_name')->where('company_id',
$userCompany)->where('is_current', 1)->first();
$employees = DB::table('hr_employees')->select('id')->where('id', $userEmployee)->first();
$goal = AppraisalGoal::findOrFail($id);
$goaltypes = AppraisalGoalType::where('company_id', $userCompany)->get();
$goaldetails = AppraisalGoalDetail::where('appraisal_goal_id', $id)->get();
$appraisalgoaltype = DB::table('appraisal_goals')->select('goal_type_id')->where('id', $id)->first()->goal_type_id;
// appraisal score
$scoreidentities = DB::table('appraisal_identity')->select('id')->where('company_id', $userCompany)->where('is_current', 1)->first()->id;
$child = DB::table('appraisal_goal_types')->where('company_id', $userCompany)->where('id',$appraisalgoaltype)->first();
$parentid = DB::table('appraisal_goal_types')->select('parent_id')->where('company_id', $userCompany)->where('id',$appraisalgoaltype)->first()->parent_id;
if(empty($child))
{
abort(404);
}
$weightedscore = 0;
$weightedscore = DB::table('appraisal_goals')->select(DB::raw("IFNULL(SUM(weighted_score),0) as weighted_score"))->where('appraisal_identity_id', $scoreidentities)->where('employee_id', $userEmployee)->where('parent_id', $parentid)->first();
$maxscore = DB::table('appraisal_goal_types')->select('max_score')->find($child->parent_id);
return view('appraisal.appraisal_goals.edit')
->with('goaltypes', $goaltypes)
->with('goal', $goal)
->with('goaldetails', $goaldetails)
->with('categories', $categories)
->with('identities', $identities)
>with('weightedscore', $weightedscore)
->with('maxscore', $maxscore)
->with('employees', $employees);
}
Просмотр
<input type="hidden" id="max_score" value="{{$maxscore->max_score}} class="form-control" >
<input type="hidden" id="weighted_score" value="{{$weightedscore->weighted_score}} class="form-control" >
Когда я запускаю код, я получаю эту ошибку :
Аргумент 2, переданный в with (), должен быть вызываемым или нулевым, объект задан
Я обнаружил, что ошибка находится в этой строке:
>with('weightedscore', $weightedscore)
->with('maxscore', $maxscore)
Когда я сделал:
d ie (var_dump ($ weightedscore));
Я получил:
объект (stdClass) # 2494 (1) {["weighted_score"] => string (2) "40"}
и когда я это сделал:
d ie (var_dump ($ maxscore));
Я получил:
object (stdClass) # 2516 (1) {["max_score"] => int (75 )}
Как мне решить эту проблему?
Спасибо.