Category : orm

I’ve a problem when sorts data from largest to smallest from table relations that do not necessarily have a relationship with PHP Laravel Eloquent. Table: items |—————————| | id | name | price | |—————————| | 1 | Samsung | 70.000 | | 2 | iPhone | 90.000 | | 3 | Nokia | 50.000 ..

Read more

I am trying to get the first transaction that was recorded close to a particular date using the Laravel 8 DB Facade. I have tried to use it in the following manner $lastest_transaction = DB::table($targetTable) ->where(‘date’, ‘<=’, date(‘F’)) ->where(‘id’, ‘=’, $client->id) ->where(‘branch’, ‘=’, session(‘branch’)) ->get(); but it’s not giving me the correct transaction. Sourc..

Read more

I have done much research about this but I can’t fetch the pivot table as I want. I want to just fetch the measurement value from the pivot table-like structure you can see. Please check my all details first then you know what I want to show. Model MeasurementPart.php public function customers(){ return $this->belongsToMany(Customer::class, ‘customer_measurements’, ..

Read more

I would like to preface this by saying that I’m new to Laravel and Eloquent ORM. I’m currently using Laravel 5.8. I have a Model ReturnRequestthat has a ReturnRequestCustomer, a ReturnRequestShippingAddress, and a ReturnRequestAddress. The relations look like so: ReturnRequest class ReturnRequest { public function customer() { return $this->hasOne(ReturnRequestCustomer::class); } public function shippingAddress() { return ..

Read more

in my Laravell Application, I need submodels of the base ORM model, for specific types of item in my DB which is specified in ‘type’ collum in DB in my base model, I use this override for function newFromBuilder //OVERIDES public function newFromBuilder($attributes = [], $connection = null) { $class = "AppModels" . ucfirst($attributes->type); if ..

Read more

I’m creating an API. In this repository there’s a method called show() where a contact is returned. The user must provide an ID of a contact and can provide an array of relationships to be loaded and an array of the contact’s attributes called fields. return $this->contacts::with($request->relationships)->findOrFail($request->id, $request->fields); But when $request->fields is provided all the ..

Read more

We have two entities using InheritanceType("SINGLE_TABLE"). The parent class that defines the DiscriminatorMap is Note. The two children are Comment and Message. There are cases where we would like to copy a comment from a message. We wanted to indicate where this occurred so we added a column called copied_to_id. And every time we copy ..

Read more

I have a challenge in laravel polymorph many to many relationship. i am using this database architecture products id – integer name – string price – float articles id – integer title – string description – string tags id – integer name – string taggables tag_id – integer taggable_id – integer taggable_type – string how ..

Read more

I’m a newbie in Laravel and I tried to connect two tables with SUM of one column along with other columns, But it’s returned an error and I don’t know how to fix that.. Please help me to resolve the issue. Any help is appreciated … $sinv =DB::table(‘salesinvoices’) ->leftJoin(‘customers’,’customers.id’,’=’,’salesinvoices.customer’) ->select(DB::raw(‘sum((salesinvoices.grand_total)-(salesinvoices.isslnrtn_amt)) as sumgrand’),’customers.short_name’) ->where(‘salesinvoices.is_deleted’,’0′) ->where(‘salesinvoices.is_returned’,’!=’,’1′) ->where(‘salesinvoices.paidstatus’,’!=’,’1′) ..

Read more

I’m building a project with Laravel 8. I need to handle request parameter which contains page, limit, searchColumn, searchText, orderColumn and orderDirection. Sometimes I need to search in relations. I’ve built this system below but it doesn’t work on relationships. $query = (new Log())->newQuery(); $query->with(‘customer’, ‘domain’, ‘type’); if ($request->searchColumn != "" && $request->searchColumn != NULL) ..

Read more

I have a multitenant application, below I have 2 connections defined, one is the default that is used by the application and the other is one that is used to access the central database while I am on the tenant connection. ‘mysql’ => [ ‘driver’ => ‘mysql’, ‘url’ => env(‘DATABASE_URL’), ‘host’ => env(‘DB_HOST’, ‘127.0.0.1’), ‘port’ ..

Read more