laravel-4

Laravel 4 Eloquent returns wrong ID

有些话、适合烂在心里 提交于 2021-02-18 12:04:27
问题 I have 3 tables in my database: Campaigns Users Companies One company may have some users. One user may have some campaigns. A user (with admin rights) can do some actions with any campaign that belongs to his company. So, I want to check whether he's doing these actions with his campaign or not (in the last case I return something like "access denied"). My condition Campaign::join('users', 'users.id', '=', 'campaigns.user_id') ->where('users.company_id', '=', Auth::user()->company->id) -

Laravel 4 Eloquent returns wrong ID

为君一笑 提交于 2021-02-18 12:03:45
问题 I have 3 tables in my database: Campaigns Users Companies One company may have some users. One user may have some campaigns. A user (with admin rights) can do some actions with any campaign that belongs to his company. So, I want to check whether he's doing these actions with his campaign or not (in the last case I return something like "access denied"). My condition Campaign::join('users', 'users.id', '=', 'campaigns.user_id') ->where('users.company_id', '=', Auth::user()->company->id) -

Case-sensitive where statement in laravel

女生的网名这么多〃 提交于 2021-02-17 15:17:37
问题 How can I do a case-sensitive string match with laravel? SELECT * FROM `invites` WHERE `token`='OGwie2e2985tOEGewgu23hUFs' Can be done as Invite::where('token',$token)->first() If I want a case-sensitive match I need to use a statement like this (or similar, as far as I know): SELECT * FROM `invites` WHERE BINARY `token`='OGwie2e2985tOEGewgu23hUFs' My best guess would be: Invite::whereRaw("BINARY `token`='{$token}'")->first() but then my input is not going through a prepared statement, right?

Generate Model, Controller outside of app folder in Laravel

喜夏-厌秋 提交于 2021-02-17 02:34:33
问题 How to create controller and model files outside of app folder. For example, when we do php artisan make:model ModelName it creates Model file inside app folder. When we specify namespace like php artisan make:model SomeFolder/ModelName it creates Model file inside app/SomeFolder/ModelName. I wanted to create model files outside of app folder. How to achieve this? 回答1: I don't see the reason, but I managed to make it on my local computer by php artisan make:model ../../mOdel . Probably in

Generate Model, Controller outside of app folder in Laravel

二次信任 提交于 2021-02-17 02:32:30
问题 How to create controller and model files outside of app folder. For example, when we do php artisan make:model ModelName it creates Model file inside app folder. When we specify namespace like php artisan make:model SomeFolder/ModelName it creates Model file inside app/SomeFolder/ModelName. I wanted to create model files outside of app folder. How to achieve this? 回答1: I don't see the reason, but I managed to make it on my local computer by php artisan make:model ../../mOdel . Probably in

laravel belongsToMany Filter

て烟熏妆下的殇ゞ 提交于 2021-02-08 04:10:45
问题 I have three tables as below: users id|name|username|password roles id|name users_roles id|user_id|role_id These tables communicate via belongsToMany. I would like to find a way to select all data in “users” table except ones that their user value of "role_id" is 5 in table “users_roles”. How can I do it? 回答1: You should use whereDoesntHave() to select models that don't have a related model meeting certain criteria: $users = User::whereDoesntHave('roles', function($q){ $q->where('role_id', 5)

laravel belongsToMany Filter

那年仲夏 提交于 2021-02-08 04:10:32
问题 I have three tables as below: users id|name|username|password roles id|name users_roles id|user_id|role_id These tables communicate via belongsToMany. I would like to find a way to select all data in “users” table except ones that their user value of "role_id" is 5 in table “users_roles”. How can I do it? 回答1: You should use whereDoesntHave() to select models that don't have a related model meeting certain criteria: $users = User::whereDoesntHave('roles', function($q){ $q->where('role_id', 5)

Laravel how do I get the row number of an object using Eloquent?

梦想的初衷 提交于 2021-02-07 20:49:38
问题 I'd like to know the position of a user based on its creation date. How do I do that using Eloquent? I'd like to be able to do something like this: User::getRowNumber($user_obj); 回答1: I suppose you want MySQL solution, so you can do this: DB::statement(DB::raw('set @row:=0')); User::selectRaw('*, @row:=@row+1 as row')->get(); // returns all users with ordinal 'row' So you could implement something like this: public function scopeWithRowNumber($query, $column = 'created_at', $order = 'asc') {

Laravel how do I get the row number of an object using Eloquent?

烂漫一生 提交于 2021-02-07 20:47:30
问题 I'd like to know the position of a user based on its creation date. How do I do that using Eloquent? I'd like to be able to do something like this: User::getRowNumber($user_obj); 回答1: I suppose you want MySQL solution, so you can do this: DB::statement(DB::raw('set @row:=0')); User::selectRaw('*, @row:=@row+1 as row')->get(); // returns all users with ordinal 'row' So you could implement something like this: public function scopeWithRowNumber($query, $column = 'created_at', $order = 'asc') {

How does Laravel queue work and what if php artisan queue:listen stops

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-06 10:48:34
问题 I have installed beanstaled and its working fine with laravel. The point where I am puzzled is that we have to do php artisan queue:listen to start listening queue. Right now, I am using it on amazone ec2 instance remotely through putty. but what is i close terminal? Will the jobs created through the code will work? Is it manually calling php artisan queue:listen or php artisan queue:work all time. Which does not seems fair. If once php artisan queue:listen done, will it keep on running even