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: [] }
. Do I have to use with statement or anything? 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
<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:
protected $fillable = array('file_name','file_size','user_id');
public function personal_infos() {
return $this->belongsTo('App\personal_info', 'user_id', 'id');
}