title: laravel how to access column with number name of a table?
body: <p>I make a table with number 22 as the column name. How to access this column?</p>
  
  <p><a href="https://i.stack.imgur.com/jqGsd.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/jqGsd.jpg" alt="enter image description here"></a></p>
  
  <p>content:</p>
  
  <p><a href="https://i.stack.imgur.com/edoBY.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/edoBY.jpg" alt="enter image description here"></a></p>
  
  <p>I've tryed thest</p>
  
  <pre><code>$obj = Tablename::find(1)-&gt;first();
  $obj-&gt;22;
  $obj-&gt;'22';   //'syntax error, unexpected ''22''
  $obj-&gt;"22";
  $obj-&gt;`22`;
  $obj[22];
  $arr = $obj-&gt;toArray();
  var_dump($arr); //  array(15) { ["id"]=&gt; string(2) "25" ["out_trade_no"]=&gt; string(14) "14847080930025" ["22"]=&gt; string(0) "2"
  $arr[22];       // 'ErrorException' with message 'Undefined offset: 22'
  $arr['22'];     // 'ErrorException' with message 'Undefined offset: 22'
  $arr["22"];     // 'ErrorException' with message 'Undefined offset: 22'
  $arr[`22`];     // 'ErrorException' with message 'Undefined index: ' in
  $arr[{'22'}];   //  'syntax error, unexpected '{', expecting ']'' in
  </code></pre>
  
  <p>none works.</p>
  
  <p>edited as the answer implemented: also get null.</p>
  
  <pre><code>var_dump($orders[0]);
  var_dump($orders[0]-&gt;id);
  var_dump($orders[0]-&gt;{'22'});
  $col = '22';
  $res = $orders[0]-&gt;{$col};
  var_dump($res);
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>object(Order)#537(21){
      [
          "connection": protected
      ]=&gt;NULL[
          "table": protected
      ]=&gt;NULL[
          "primaryKey": protected
      ]=&gt;string(2)"id"[
          "perPage": protected
      ]=&gt;int(15)[
          "incrementing"
      ]=&gt;bool(true)[
          "timestamps"
      ]=&gt;bool(true)[
          "attributes": protected
      ]=&gt;array(15){
          [
              "id"
          ]=&gt;string(2)"25"[
              "out_trade_no"
          ]=&gt;string(14)"14847080930025"[
              "22"
          ]=&gt;string(1)"2"[
              "user_id"
          ]=&gt;string(2)"49"[
              "product_name"
          ]=&gt;string(4)"test"[
              "amount"
          ]=&gt;string(1)"3"[
              "fee"
          ]=&gt;string(4)"0.03"[
              "address_id"
          ]=&gt;string(1)"3"[
              "trade_status"
          ]=&gt;string(13)"TRADE_SUCCESS"[
              "express_name"
          ]=&gt;string(0)""[
              "express_no"
          ]=&gt;string(0)""[
              "buyer_email"
          ]=&gt;string(0)""[
              "modify_at"
          ]=&gt;string(19)"2017-01-18 10:54:53"[
              "created_at"
          ]=&gt;string(19)"2017-01-18 10:54:53"[
              "updated_at"
          ]=&gt;string(19)"2017-01-18 10:55:26"
      }[
          "original": protected
      ]=&gt;array(15){
          [
              "id"
          ]=&gt;string(2)"25"[
              "out_trade_no"
          ]=&gt;string(14)"14847080930025"[
              "22"
          ]=&gt;string(1)"2"[
              "user_id"
          ]=&gt;string(2)"49"[
              "product_name"
          ]=&gt;string(4)"test"[
              "amount"
          ]=&gt;string(1)"3"[
              "fee"
          ]=&gt;string(4)"0.03"[
              "address_id"
          ]=&gt;string(1)"3"[
              "trade_status"
          ]=&gt;string(13)"TRADE_SUCCESS"[
              "express_name"
          ]=&gt;string(0)""[
              "express_no"
          ]=&gt;string(0)""[
              "buyer_email"
          ]=&gt;string(0)""[
              "modify_at"
          ]=&gt;string(19)"2017-01-18 10:54:53"[
              "created_at"
          ]=&gt;string(19)"2017-01-18 10:54:53"[
              "updated_at"
          ]=&gt;string(19)"2017-01-18 10:55:26"
      }[
          "relations": protected
      ]=&gt;array(0){
  
      }[
          "hidden": protected
      ]=&gt;array(0){
  
      }[
          "visible": protected
      ]=&gt;array(0){
  
      }[
          "appends": protected
      ]=&gt;array(0){
  
      }[
          "fillable": protected
      ]=&gt;array(0){
  
      }[
          "guarded": protected
      ]=&gt;array(1){
          [
              0
          ]=&gt;string(1)"*"
      }[
          "dates": protected
      ]=&gt;array(0){
  
      }[
          "touches": protected
      ]=&gt;array(0){
  
      }[
          "observables": protected
      ]=&gt;array(0){
  
      }[
          "with": protected
      ]=&gt;array(0){
  
      }[
          "morphClass": protected
      ]=&gt;NULL[
          "exists"
      ]=&gt;bool(true)[
          "softDelete": protected
      ]=&gt;bool(false)
  }string(2)"25"NULLNULL
  </code></pre>
  
  <p>Edit: acording to <a href="https://stackoverflow.com/a/42330167/6521116">Paras's comment</a></p>
  
  <p><a href="https://i.stack.imgur.com/UsYtt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UsYtt.png" alt="enter image description here"></a></p>
  
  <p>Edit2: 
  to make question simple and clear:</p>
  
  <p>migration:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class Test extends Migration {
  
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('tests', function($table)
          {
              $table-&gt;increments('id');
              $table-&gt;integer('22');
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          //
      }
  
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>&lt;?php
  class Test extends Eloquent
  {
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function show()
  {
      $tests = Test::all();
      foreach($tests as $test)
      {
          Log::info($test-&gt;id);
          Log::info($test-&gt;{'22'});
          Log::info($test-&gt;{"22"});
          Log::info($test-&gt;getAttribute("22"));
      }
  }
  </code></pre>
  
  <p>data table:</p>
  
  <p><a href="https://i.stack.imgur.com/lHy7a.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lHy7a.png" alt="enter image description here"></a></p>
  
  <p>and the log:</p>
  
  <pre><code>[2017-02-25 09:16:48] production.INFO: 1 [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  [2017-02-25 09:16:48] production.INFO: 2 [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  [2017-02-25 09:16:48] production.INFO:  [] []
  </code></pre>