Matías Cánepa
Matías Cánepa

Reputation: 5974

get one row of dummy data with eloquent

Take this example

$result = Players::select("first_name", "last_name")->where("some_field", "some_value");

That returns a Illuminate\Database\Eloquent\Builder

Now I would like to "simulate" that same thing but with dummy data, so I did this

$result = Players::select(DB::raw("'john', 'doe'"));

That works, but when the query runs, if the the players table has 10 rows I get 10 rows filled with john doe and I only need just one.

I've tried doing

$result = Players::select(DB::raw("'john', 'doe'"))->limit(1);

but that has no effect

How can I get only 1 row of dummy data? Taking into account that $result must return a Illuminate\Database\Eloquent\Builder

Upvotes: 0

Views: 566

Answers (1)

Armin Sameti
Armin Sameti

Reputation: 181

if you want to do it in your suggested way i think this should work :

$result = Players::select(DB::raw("'john' as first_name , 'doe' as last_name"))->take(1);

Upvotes: 0

Related Questions