I make a table with number 22 as the column name. How to access this column?
content:
I\'ve tryed thest
$obj = Tablename::f
Try this:
$obj->getAttributeValue("22");
Please post the error if it doesn't work
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);
}
}
$arr= Tablename::where('id', 1)->lists('22', 'id')->toArray();
$result = $arr[1];
As 1 is the $id var. I tried it in my localhost and it works
Try this:
$col = '22';
$res = $obj->{$col};
var_dump($res);
Try use pluck()
$plucked = $collection->pluck('22');
$plucked->all();
Try to use where:
Tablename::where('22','=','value')->first();