Advance using of eloquent in Laravel 4

This article is going to show you some advance using of eloquent that didn’t show in laravel documentation.

“SELECT” Query

SELECT DISTINCT category FROM phones LIMIT 20

Phone::select(array("category"))->distinct()->take(20)->get();

SELECT id,name FROM phones ORDER BY created_at DESC

Phone::orderBy("created_at","desc")->get(array("id,name"));

SELECT * FROM phones WHERE status=”publish” AND name LIKE “John%”

Phone::select("*")->where("status","=","publish")->where("name","like","John%")->get()

SELECT * FROM phones WHERE (id BETWEEN 1 AND 100) OR (image not like ‘%iPhone%’);

Phone::whereBetween("id",array(1,10))->orWhere("image","not like", "%iPhone%")->get();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s