[英]get function returning empty array laravel
I need some help getting my user_id from my pdf_files table, but for some reason it keep giving me an empty array when I try using $request = all()
--> return me {}
and dd($downloads)
return me this Collection {#233 ▼ #items: [] }
. 我需要一些帮助,以从pdf_files表中获取我的user_id,但是由于某些原因,当我尝试使用
$request = all()
->返回我{}
和dd($downloads)
时,它一直给我一个空数组{#233 ▼ #items: [] }
。 Do I have to use with statement or anything? 我必须使用with语句或其他任何东西吗? I saw some people using it but do I really need it?
我看到有人使用它,但我真的需要吗? Thanks for helping
感谢您的帮助
Code: 码:
Controller: 控制器:
public function downfunc(Request $request){
// $downloads = new pdfFile;
$downloads=pdfFile::where('user_id', $request->user_id)->get();
//$downloads=DB::table('pdf_files')->get(); --> this code return results
//dd($downloads);
//return $request->all();
return view('download.viewfile',compact('downloads'));
} }
download.blade.php download.blade.php
<table class="table table-bordered">
<thead>
<th>Name of File</th>
<th>Action</th>
</thead>
<tbody>
@foreach($downloads as $down)
<tr>
<td>{{$down->file_name}}</td>
<td>
<a href="download/{{$down->file_name}}" download="{{$down->file_name}}">
<button type="button" class="btn btn-primary">
<i class="glyphicon glyphicon-download">
Download
</i>
</button>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
pdfFile model: pdf文件模型:
protected $fillable = array('file_name','file_size','user_id');
public function personal_infos() {
return $this->belongsTo('App\personal_info', 'user_id', 'id');
}
Please make sure your $request->user_id
is valid 请确保您的
$request->user_id
有效
You can check by run sql manually. 您可以通过手动运行sql进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.