我想从我控制器内的另一个类调用函数payrollProcess。
这是我的代码:
public function save(Request $request, $obj = null)
{
PayrollHelper::payrollProcess($PayrollPeriod);
return view('payroll_process.form');
}
这是payrollHelper类代码:
<?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);
}
}
}
?>
运行时出现此错误。调用未定义的方法App \ Helpers \ PayrollHelper :: payrollProcess()
任何想法?
答案 0 :(得分:0)
在PayrollHelper
课程中,您已在控制器中定义了processPayroll
方法
public function save(Request $request, $obj = null)
{
PayrollHelper::payrollProcess($PayrollPeriod);
return view('payroll_process.form');
}
您正在访问未定义的方法