0
votes

I want to call function payrollProcess from another class inside my controller.

here's my code :

 public function save(Request $request, $obj = null)
 {
  PayrollHelper::payrollProcess($PayrollPeriod);
  return view('payroll_process.form');
 }

and this is payrollHelper class code :

<?php

namespace App\Helpers;

use App\Helpers\Exceptions\ValidationException;
use App\Models\Config;
use App\Models\Driver;
use App\Models\DriverPayable;
use App\Models\PayrollPeriod;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Facades\Log;

final class PayrollHelper {
public static function processPayroll(PayrollPeriod $payrollPeriod) 
{
    try {
        $drivers = Driver::where('active', true)->get();
        foreach ($drivers as $driver) {
            $payable = $payrollPeriod->driverPayables()
                        ->where('driver_id', $driver->id)->first();
            if (!$payable) {
                $payable = new DriverPayable;
            }
            $payable->payrollPeriod()->associate($payrollPeriod);
            $payable->driver()->associate($driver);
            if (!$payable->save()) {
                \Log::info($payable->errors());
                throw new ValidationException($payable->errors());
            }
        }
    } catch (Exception $e) {
        Log::error($e);
        SessionHelper::setMessage(
            'Unable to process payroll, Please contact system Administrator'
        );
    } catch (ValidationException $e) {
        Log::info($e->errors);
        SessionHelper::setMessage($e->errors);
    }
}


}

?>

I got this error when i run it. Call to undefined method App\Helpers\PayrollHelper::payrollProcess()

any idea ?

1
have defined use App\Helpers; in your controllerVision Coderz
yes i did : use App\Helpers\PayrollHelper;Andrew Vanusi
hey payrollProcess() method not there in your PayrollHelperVision Coderz
if only use App\Helpers; it says Class 'App\Http\Controllers\PayrollHelper' not found.Andrew Vanusi
PayrollHelper::processPayroll($PayrollPeriod);Vision Coderz

1 Answers

0
votes

In PayrollHelper class you have defined processPayroll method so in your controller

 public function save(Request $request, $obj = null)
 {
  PayrollHelper::payrollProcess($PayrollPeriod);
  return view('payroll_process.form');
 }

you are accessing undefined method