laravel:如何获得雄辩模型的列名? [英] laravel:how to get columns name of eloquent model?
本文介绍了laravel:如何获得雄辩模型的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是laravel 5.2,我想获取所选雄辩模型的所有列(属性)名称,有没有办法做到这一点?
I am using laravel 5.2 ,i want to get all the column (attribute) name of selected eloquent model,is there way to do this?
以下是我在控制器方法中的代码
following is my code in controller method
if($request->method=="edit")
{
/*we are in edit mode details of given news ID should be attached*/
$curNews=News::find($request->newsID);
if($curNews==null)return back()->withErrors(["Unable to Edit News:No Data Found For Given News ID"]);
foreach((array)$curNews->attributes as $key=>$val)
{
$data[$key]=$val;
}
}
return view('adminarea.news.news-addedit',$data);
推荐答案
$columns = Schema::getColumnListing('users'); // users table
dd($columns); // dump the result and die
这篇关于laravel:如何获得雄辩模型的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文