0

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');
}
1
  • I just tried using count() but it doesn't work also Commented Oct 27, 2017 at 2:49

1 Answer 1

1

Please make sure your $request->user_id is valid

You can check by run sql manually.

Sign up to request clarification or add additional context in comments.

3 Comments

It return me null, but in my database i have the data inside, how did i even get null?
You need to check your request (from your view or url), and your routes config.
Oh I found my problem it was in the route, thank you so much for helping me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.