-1

I have a helper class name common.php in App\Helpers folder. I want to use DB:: facade here to use some db table. In helper method My code is -

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

But this not working. Following error has been arrived.

Following error has been arrived.

So how can i solve this?

mahbub
  • 103
  • 1
  • 3
  • 13
  • Could you share the whole common.php file content? Your current amount of info is not enough – Techno Mar 03 '22 at 13:56
  • *But this not working* - this should pretty much never appear in a question without some supporting info. What does "not working" mean? Is it throwing an exception? Are you not getting expected results? You need to clearly explain the behavior you're seeing in order for us to give any idea of what's going wrong. – Brian Thompson Mar 03 '22 at 14:17
  • I have updated my question. – mahbub Mar 03 '22 at 14:38
  • Use `use Illuminate\Support\Facades\DB;` instead of `use DB;` and try again – glinda93 Mar 03 '22 at 14:46

1 Answers1

0

Change your using to: Illuminate\Support\Facades\DB;