laravel how to access column with number name of a table?

后端 未结 12 1270
闹比i
闹比i 2020-12-18 19:11

I make a table with number 22 as the column name. How to access this column?

content:

I\'ve tryed thest

$obj = Tablename::f         


        
12条回答
  •  一整个雨季
    2020-12-18 19:49

    Best way is NOT to use Integer as a fieldname. It is bad praxis. But if you need, you should access the database with raw method:

    public function show()
    {
         $tests = DB::table('test')
            ->select("22 as twentytwo")
            ->get();
        foreach($tests as $test){
            Log::info($test->twentytwo);
        }
    }
    

提交回复
热议问题