eloquent

Laravel 4 inherited attributes are null

坚强是说给别人听的谎言 提交于 2019-12-22 18:12:39
问题 I have a model, which inherits from the Toddish\Verify Laravel package (https://github.com/Toddish/Verify-L4/blob/master/src/Toddish/Verify/Models/User.php) All I want to do is add some attributes: use Toddish\Verify\Models\User as VerifyUser; class User extends VerifyUser { public function __construct (array $attributes = array()) { parent::__construct($attributes); $this->fillable = array_merge ($this->fillable, array( 'salutation', 'title', 'firstname', 'lastname', 'phonenumber',

Getting the current row's rank with Laravel

落爺英雄遲暮 提交于 2019-12-22 17:40:08
问题 In my Laravel 4 app, my users table has a votes column. I'd like to find the current user's rank. I can already get the top 10 users with User::orderBy('votes', 'desc')->take(10) , but I'd like to display the current user's rank below that list. Ideally, this would go something like: Auth::user()->rank('orderBy', 'votes', 'desc'); I get the logged in user, I ask for his rank assuming I order the users table by votes. Does anybody know if there's some way I can do this with Eloquent? 回答1:

Laravel pessimistic lock not working like supposed to

﹥>﹥吖頭↗ 提交于 2019-12-22 17:37:09
问题 I'm developing a little shopping website for entertainment purpose but I'm intending to apply the same code to a possible real shop website in the future. So I have these "slots" that are meant to be bought, like a reservation slot for saving seats with numbers. So people will buy the slots and save the seats, but I'm facing a race condition problem, even though I'm using lockForUpdate method, I can buy more slots than I have balance for. My piece of code for when the user clicks "buy":

Laravel 4.1 Eloquent - use a custom connection with whereHas

故事扮演 提交于 2019-12-22 15:00:30
问题 I am using MSSQL having 2 connections named seven_ora (which a User model's table is in), and sho (which a Character model's table is in). A user hasMany characters, and a character belongsTo user. When I try: Character::whereHas('User', function($q) { $q->where('gm', 1); }); It seems to use the same connection as Character. And it seems that the closure in whereHas is a Query\Builder? I expected the whereHas to use the respective set connection of whatever model it is referring to. Is there

How to trigger Eloquent Manager in Slim 3.1 Dependency Injection

我的梦境 提交于 2019-12-22 14:54:08
问题 I have write my code to instantiate Eloquent Capsule/Manager using slim DI like this $container['db'] = function ($c) { $settings = $c->get('database'); $db = new \Illuminate\Database\Capsule\Manager; $db->addConnection($settings); $db->setAsGlobal(); $db->bootEloquent(); return $db; } And I have my route like this $app->get('/adduser', function() { $user = new Users; $user->name = "Users 1"; $user->email = "user1@test.com"; $user->password = "My Passwd"; $user->save(); echo "Hello, $user-

Laravel Eloquent double value stored in database returned rounded

心已入冬 提交于 2019-12-22 13:33:16
问题 I have following value stored in MySQL database 23456789123,45678 and when I'm getting this value using magic variable I'm getting 23456789123,457 as a value. I have tried $cast variable in Model: protected $casts = [ 'previous_value' => 'double(16,5)', ] but that did not helped. Much appreciate on any help in this regards. 回答1: The problem is not with Laravel, it is actually PHP that is rounding this. In the PHP documentation you can see that the default precision is 14 , which you are

Laravel 5 - Using Mockery to mock Eloquent model

被刻印的时光 ゝ 提交于 2019-12-22 12:16:09
问题 Been looking all over the internet but don't seem to find an answer to my problem. I've been diving into testing controllers in Laravel using PHPUnit and Mockery. However, I don't seem to get my Eloquent based models mocked correctly. I did manage to mock my Auth::user() the same way, although this is not used in the test below. Function in AddressController that needs to be tested: public function edit($id) { $user = Auth::user(); $company = Company::where('kvk', $user->kvk)->first();

Laravel 5 - Using Mockery to mock Eloquent model

蓝咒 提交于 2019-12-22 12:16:09
问题 Been looking all over the internet but don't seem to find an answer to my problem. I've been diving into testing controllers in Laravel using PHPUnit and Mockery. However, I don't seem to get my Eloquent based models mocked correctly. I did manage to mock my Auth::user() the same way, although this is not used in the test below. Function in AddressController that needs to be tested: public function edit($id) { $user = Auth::user(); $company = Company::where('kvk', $user->kvk)->first();

Change raw query join into laravel Eloquent

若如初见. 提交于 2019-12-22 11:29:32
问题 I have two models: $modelMain = "SearchPages"; //table_name : search_pages $modelSites = "Site"; // table_name : sites I initially had a below query for getting count from only one model $modelMain : $records = $modelMain:: select(DB::raw("COUNT(DISTINCT {$columnRecordedOn}) as records_count")) ->groupBy($columnRecordedOn, $columnSiteId) ->get(); Now, I need to join it with 2nd model $modelSites whoese table name is sites in order to check status column in sites if its 1. I modified the query

Soft deleting in pivot with sync method laravel

别等时光非礼了梦想. 提交于 2019-12-22 08:59:44
问题 I want sync some relation in User's Table and I don't want to Laravel delete the row, I want make some updates on that row (Like fill the deleted_at), I searched so far and only solution i found is that to override sync method. So how i can override the sync method to update the row? Or whats another solution for this problem? EDITED: I know the problem is with detach method, If i could override the detach It will be solved! Thanks 回答1: I think you were looking for this method. $user->your