eloquent

Laravel Raw query paginate; raw query to eloquent object

╄→尐↘猪︶ㄣ 提交于 2020-01-06 13:10:39
问题 select '0000-00-00' as date, 'Opening Balance' as narration, (SELECT debit FROM `account_sub_journal` where id=1)as debit, (SELECT credit FROM `account_sub_journal` where id=1)as credit, '0' as transaction_entry_id,'0' as account_sub_journal_id UNION SELECT * FROM `ledgertransactions` where account_sub_journal_id = 1 and `date` BETWEEN '2014-04-01' and '2014-04-10' I currently do this as a static function in model. I couldn't paginate this since laravel says it is not an object public static

Laravel Raw query paginate; raw query to eloquent object

你。 提交于 2020-01-06 13:10:19
问题 select '0000-00-00' as date, 'Opening Balance' as narration, (SELECT debit FROM `account_sub_journal` where id=1)as debit, (SELECT credit FROM `account_sub_journal` where id=1)as credit, '0' as transaction_entry_id,'0' as account_sub_journal_id UNION SELECT * FROM `ledgertransactions` where account_sub_journal_id = 1 and `date` BETWEEN '2014-04-01' and '2014-04-10' I currently do this as a static function in model. I couldn't paginate this since laravel says it is not an object public static

Eloquent update and limit

我与影子孤独终老i 提交于 2020-01-06 12:26:04
问题 I could not figure out how can i use both update and limit methods in laravel eloquent orm. $affectedRows = Promo::where('used','=',0) ->update(array('user_id' => Auth::user()->id)) ->limit(1); // Call to a member function limit() on a non-object //->take(1); // Call to a member function take() on a non-object I tried both limit and take methods. I want to do only one result will be update. But i think, i can not use limit or take methods on update. Is there any way to update only one row via

Laravel 5.5 whereDate/whereTime not add quotation

假如想象 提交于 2020-01-06 09:09:12
问题 Appointment::whereDate('schedule_date', '=', date('Y-m-d')) ->whereTime('time_from', ' <= ', date('H:i:s')) ->whereTime('time_to', ' <= ', date('H:i:s', strtotime('+1 hour'))) ->get(); When this code is running on the production server, there's no response. Perhaps it's for quotation? But how can I add this? I mean quotation (single/double). 回答1: This appears to be a possible bug in laravel not enclosing the date in quotes, this results in it treating the Y-m-d as a maths operation. whereDate

Laravel set an Automatic WHERE Clause

痞子三分冷 提交于 2020-01-06 08:16:12
问题 I use models that extend a generic_model, which in turn extends Eloquent (so that I have several crud methods I use already set to be inherited). A lot of the tables I use invoke soft delete, which needs a WHERE clause of... WHERE deleted = 0 Is there a way to make Laravel behave in such a way that this WHERE clause is automatically included in all queries and all queries to objects that are related to one another? e.g. pages where id = 5 and deleted = 0 and then... images where page_id = 5

Laravel Eager Loading, multiple same hasOne relations

99封情书 提交于 2020-01-06 08:14:27
问题 I have 2 simple models. First, one is called Builds and the second one is called SlotOptions. Each build can have like 5 assigned slots. class BuildDB extends Model And has 5 such relations slot1-5 and id changes to slot1-5_id public function slot1() { return $this->hasOne('\App\SlotOptions', 'id', 'slot1_id'); } In the controller I call it such way; BuildDB::with([ 'slot1', 'slot2', 'slot3', 'slot4', 'slot5'])->find(5); \App\SlotOptions model doesn't contain any extra coding. This generates

Laravel model mutator not working when using attach to save on pivot table

左心房为你撑大大i 提交于 2020-01-06 07:07:40
问题 I have a model mutator on my pivot table like so: When I save to it like this: $account_transaction->subcategories()->attach($water_subcategory->id, ['amount'=>56]); The database shows 56, instead of 5600. <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class SubcategoryTransaction extends Model { protected $table = 'subcategory_transaction'; protected $fillable = ['amount']; public function getAmountAttribute($value) { if ($value) { $value = $value / 100; return $value; }

Load Laravel Eloquent relationship during creation

戏子无情 提交于 2020-01-06 06:29:27
问题 I've read the docs at https://laravel.com/docs/5.7/eloquent-relationships#eager-loading but am still having trouble. Why does the else branch of this function not return a \App\Models\Customer object with an attached \App\Models\Contact ? /** * * @param \App\Models\Contact $contact * @param string $msg * @return \App\Models\Customer */ public function createCustomerIfNecessary($contact, &$msg) { if ($contact->customer) { return $contact->customer; } else { $customer = new \App\Models\Customer

Method 'references' not found in Illuminate\Support\Fluent in Laravel 5.8

做~自己de王妃 提交于 2020-01-06 06:25:39
问题 I am using Laravel 5.8 with PHP 7.1 It gives the warning with the references() function. $table->foreign('student_id')->references('student_id')->on('student'); The error is: Warning:(52, 45) Method 'references' not found in Illuminate\Support\Fluent Thanks in advance. 回答1: It's your IDE complaining not a laravel issue. Add this code to the top of your _ide_helper.php file. namespace Illuminate\Support{ /** * @method Fluent first() * @method Fluent after($column) * @method Fluent change() *

Method 'references' not found in Illuminate\Support\Fluent in Laravel 5.8

£可爱£侵袭症+ 提交于 2020-01-06 06:25:27
问题 I am using Laravel 5.8 with PHP 7.1 It gives the warning with the references() function. $table->foreign('student_id')->references('student_id')->on('student'); The error is: Warning:(52, 45) Method 'references' not found in Illuminate\Support\Fluent Thanks in advance. 回答1: It's your IDE complaining not a laravel issue. Add this code to the top of your _ide_helper.php file. namespace Illuminate\Support{ /** * @method Fluent first() * @method Fluent after($column) * @method Fluent change() *