App\Helpers フォルダーにヘルパー クラス名 common.php があります。ここで DB:: ファサードを使用して、いくつかの db テーブルを使用したいと考えています。ヘルパーメソッドで私のコードは -
<?php
use DB;
function ref_number()
{
$last_row = DB::table('model_table')->latest('id')->first();
if($last_row) {
$ref = explode('-', $last_row->ref);
if($ref[0] === date('y')) {
// if running year
$ref = $ref[1] + 1;
$ref = date('y') .'-'. $ref;
}
else{
$ref = date('y') .'-'. 1; // if new year
}
}
else{
$ref = date('y') .'-'. 1; // if first data
}
return $ref;
}
しかし、これは機能しません。以下のエラーが届きました。
どうすればこれを解決できますか?