Tom Morison
Tom Morison

Reputation: 582

User::where returns null collection

I am trying to build a profile section of my website where I can take the username from the URL and query my database for that username. Either the other questions I have read are out of date or I am doing something wrong. I run the following Eloquent command in php artisan tinker

App\User::where('name', 'Tom');

However, when I run this command in my terminal, I get a blank eloquent collectioion. I am confused. Here is where I got my information for the where query: Find User in Laravel by Username

Upvotes: 0

Views: 77

Answers (1)

skrilled
skrilled

Reputation: 5371

As far as I can see in documentation (https://laravel.com/docs/5.3/queries) to return an actual row you need to use the first method, or to return several rows the get method.

This code would return the first instance of name='Tom':

App\User::where('name', 'Tom')->first();

If you're trying to get all the rows equal to Tom, then you would do this:

App\User::where('name', 'Tom')->get();

Upvotes: 2

Related Questions