Home > OS >  Non-static method Illuminate\Database\Connection::table() should not be called statically
Non-static method Illuminate\Database\Connection::table() should not be called statically

Time:12-18

I would like to fetch data from the database that my application does not set as default.

        $second = \DB::connection('second_db');
        $john = $second_::table('fruits')->where('user_id', 5)->first();

ErrorException Non-static method Illuminate\Database\Connection::table() should not be called statically

happnes.

someone said "Create an instance" I tried this

        $second = new \DB::connection('second_db');
        $record = $second::table('fruits')->where('user_id', 5)->first();

then, it happens below error.

syntax error, unexpected 'connection' (T_STRING), expecting variable (T_VARIABLE) or '$'

CodePudding user response:

Try it like this:

$john = \DB::connection('second_db')->table('fruits')->where('user_id', 5)->first();
  • Related