laravel-4

Laravel - Querybuilder with join and concat

女生的网名这么多〃 提交于 2020-08-22 12:09:41
问题 Im trying to pull all users from the users table who match a certain group in the users_groups pivot table. Im using Sentry 2 from Cartalyst btw. This works to get all users with first and last name concatenated. User::select(DB::raw('CONCAT(last_name, ", ", first_name) AS full_name'), 'id') ->where('activated', '=', '1') ->orderBy('last_name') ->lists('full_name', 'id'); when i try to change it to also filter users who do not belong to a certain group I get a syntax error. User::select(DB:

Laravel: How to get last N entries from DB

ぃ、小莉子 提交于 2020-08-20 23:10:43
问题 I have table of dogs in my DB and I want to retrieve N latest added dogs . Only way that I found is something like this: Dogs:all()->where(time, <=, another_time); Is there another way how to do it? For example something like this Dogs:latest(5); Thank you very much for any help :) 回答1: You may try something like this: $dogs = Dogs::orderBy('id', 'desc')->take(5)->get(); Use orderBy with Descending order and take the first n numbers of records. 回答2: My solution for cleanliness is: Dogs:

Laravel: How to get last N entries from DB

孤人 提交于 2020-08-20 23:10:11
问题 I have table of dogs in my DB and I want to retrieve N latest added dogs . Only way that I found is something like this: Dogs:all()->where(time, <=, another_time); Is there another way how to do it? For example something like this Dogs:latest(5); Thank you very much for any help :) 回答1: You may try something like this: $dogs = Dogs::orderBy('id', 'desc')->take(5)->get(); Use orderBy with Descending order and take the first n numbers of records. 回答2: My solution for cleanliness is: Dogs:

Can route model binding be used with RESTful controllers?

僤鯓⒐⒋嵵緔 提交于 2020-08-19 06:33:08
问题 I have been using RESTful controllers in my Laravel project. By including: Route::controller('things', 'ThingController') in my routes.php, I can define functions in the ThingController like: public function getDisplay($id) { $thing = Thing::find($id) ... } so that GETting the URL "...things/display/1" would automatically be directed to the controller function. This seems pretty handy and has been working great for me so far. I noticed many of my controller functions start with getting a