Laravel - вызов неопределенного метода Illuminate \ Database \ Query \ Builder :: ignore () - PullRequest
0 голосов
/ 20 марта 2020

В моем Laravel -5.8 проекте я написал код для динамических c полей ввода, как показано ниже:

Правила:

    public function rules()
    {
        return [
            'goal_type_id' => 
            [
                'required',
                Rule::unique('appraisal_goals')->where(function ($query) {
                return $query
                    ->ignore($this->appraisal_goal)
                    ->where('employee_id', 1)
                    ->where('appraisal_identity_id', 1);
            })
            ],              
            'goal_title' => 
            [
                'required',
                'string',
                'min:5',
                'max:100',                    
                Rule::unique('appraisal_goals')->where(function ($query) {
                return $query
                    ->ignore($this->appraisal_goal)
                    ->where('employee_id', 1)
                    ->where('appraisal_identity_id', 1);
            })
            ], 

            'appraisal_doc'             => 'nullable|mimes:doc,docx,xls,xlsx,ppt,pptx,pdf,jpg,jpeg,bmp,png,|max:5000',
            'weighted_score'            => 'required|numeric|min:0|max:500',           

            'kpi_description'           => 'required|array',
            'kpi_description.*'         => 'required',

            'activity'           => 'required|array',
            'activity.*'         => 'required',               

            'start_date.*' => [
                'required', 
                'date',
                'date_format:Y-m-d',
            ],

            'end_date.*' => [
                'required', 
                'date',
                'date_format:Y-m-d',
                'after:start_date.*'
            ],        

        ];
    }

Контроллер

    public function edit($id)
{
    $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(); 
    $categories = AppraisalGoalType::with('children')->where('company_id', $userCompany)->whereNull('parent_id')->get();
    $goal           =       AppraisalGoal::findOrFail($id);
    $goaltypes      =       AppraisalGoalType::where('company_id', $userCompany)->get(); 
    $goaldetails    =       AppraisalGoalDetail::where('appraisal_goal_id', $id)->get();
    return view('appraisal.appraisal_goals.edit')
            ->with('goaltypes', $goaltypes)
            ->with('goal', $goal)
            ->with('goaldetails', $goaldetails)
            ->with('categories', $categories)
            ->with('identities', $identities);
}

public function update(UpdateAppraisalGoalRequest $request, $id)
{
    if (! Gate::allows('appraisal_goal_edit')) {
        return abort(401);
    }
    $appraisalStartDate = Carbon::parse($request->appraisal_start_date);
    $appraisalEndDate = Carbon::parse($request->appraisal_end_date); 
    $userCompany = Auth::user()->company_id;
    $employeeId = Auth::user()->employee_id;
    $appraisal_identity_id = AppraisalIdentity::where('company_id', $userCompany)->where('is_current',1)->value('id');
    try {

    $goal = AppraisalGoal::findOrFail($id);
        $goal->goal_type_id             = $request->goal_type_id;
        $goal->appraisal_identity_id    = $appraisal_identity_id;
        $goal->employee_id              = $employeeId;  //$request->employees_id;
        $goal->weighted_score           = $request->weighted_score;
        $goal->goal_title               = $request->goal_title;
        $goal->goal_description         = $request->goal_description;
        $goal->company_id               = Auth::user()->company_id;
        $goal->updated_by               = Auth::user()->id;
        $goal->updated_at               = date("Y-m-d H:i:s");
        $goal->is_active                = 1;

        $parentids = DB::table('appraisal_goal_types')->select('parent_id')->whereNotNull('parent_id')->where('company_id', $userCompany)->where('id', $request->goal_type_id)->first();
        $goal->parent_id           = 1;           

             if ($request->appraisal_doc != "") {
                 $appraisal_doc = $request->file('appraisal_doc');
                 $new_name = rand() . '.' . $appraisal_doc->getClientOriginalExtension();
                 $appraisal_doc->move(public_path('storage/documents/appraisal_goal'), $new_name);
                 $goal->appraisal_doc = $new_name;
            } 

            $goal->save();                

    AppraisalGoalDetail::where('appraisal_goal_id', $id)->delete();

       foreach ( $request->activity as $key => $activity){
            $startDate = Carbon::parse($request->start_date[$key]);
            $endDate = Carbon::parse($request->end_date[$key]);

            $goaldetail = new AppraisalGoalDetail();
            $goaldetail->kpi_description            = $request->kpi_description [$key];
            $goaldetail->appraisal_doc              = $request->application_doc[$key];
            $goaldetail->activity                   = $request->activity[$key];
            $goaldetail->start_date                 = $startDate ->toDateTimeString();
            $goaldetail->end_date                   = $endDate->toDateTimeString();                
            $goaldetail->appraisal_goal_id          = $goal->id;
            $goaldetail->appraisal_identity_id      = $goal->appraisal_identity_id;
            $goaldetail->employee_id                = $goal->employee_id;                
            $goaldetail->company_id                 = Auth::user()->company_id;
            $goaldetail->updated_by                 = Auth::user()->id;
            $goaldetail->updated_at                 = date("Y-m-d H:i:s");
            $goaldetail->is_active                  = 1;
            $goaldetail->save();
         }
        $min_date = AppraisalGoalDetail::select('start_date')->where('appraisal_goal_id', $goal->id)->min('start_date');
        $max_date = AppraisalGoalDetail::select('end_date')->where('appraisal_goal_id', $goal->id)->max('end_date'); 
        $parentid = AppraisalGoalType::select('parent_id')->whereNotNull('parent_id')->where('company_id', $userCompany)->where('id', $goal->goal_type_id)->first();          

        $goal->update([
             'appraisal_start_date' => $min_date,
             'appraisal_end_date'   => $max_date,
             'parent_id'            => $parentid->parent_id
                 ]);            

            Session::flash('success', 'Appraisal Goal is updated successfully');
            return redirect()->route('appraisal.appraisal_goals.index');
    } catch (Exception $exception) {

            Session::flash('danger', 'Appraisal Goal update failed!');
            return redirect()->route('appraisal.appraisal_goals.index');
    }
}

В колонке редактирования, когда я нажимаю на кнопку отправить для обновления данных, я получаю эту ошибку:

Вызов неопределенного метода Illuminate \ Database \ Query \ Builder :: ignore ()

Я также вижу:

App \ Http \ Requests \ AppraisalGoal \ UpdateAppraisalGoalRequest App \ Http \ Requests \ Appraisal \ AppraisalGoal {closure}

и

Подсветка \ Проверка \ DatabasePresenceVerifier Подсветка \ Проверка {закрытие}

Как мне решить эту проблему?

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...