-1

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;
}

しかし、これは機能しません。以下のエラーが届きました。

以下のエラーが届きました。

どうすればこれを解決できますか?

4

1 に答える 1

0

使用方法を次のように変更します。Illuminate\Support\Facades\DB;

于 2022-03-03T15:18:13.110 に答える