[英]How to sort coloms in result using laravel eloquent
我有一個結果集,包括以下 coloms 我的查詢是 Employee::select('lastname', fisrtname,email,id) 結果集按此順序出現 Id FistName Lastname Email 當我渲染 colom 時,它以相同的順序給我結果。 我想要如下結果姓氏 結果 ...
[英]How to sort coloms in result using laravel eloquent
我有一個結果集,包括以下 coloms 我的查詢是 Employee::select('lastname', fisrtname,email,id) 結果集按此順序出現 Id FistName Lastname Email 當我渲染 colom 時,它以相同的順序給我結果。 我想要如下結果姓氏 結果 ...
[英]Laravel LoadSum() base on relation return also model data, how can I prevent it?
我遇到了一個問題。 當我嘗試根據關系加載 Sum 結果時,它也會返回模型數據。 如何只歸檔特定數據? 這是我的查詢。 我在這里得到了什么。 我想期待什么 謝謝你 我試過過濾數據,但這種方式行不通。 我還沒有找到解決問題的線索。 ...
[英]How to combine multiple WHERE condidtions in WITH and WHEREHAS in Laravel Eloquent query
在下面的查詢中, awarded 、 banned 、 featured和published部分被忽略了,為什么? 查詢:顯示所有精選出版書籍的列表,其中作者已獲獎且未被禁。 ...
[英]how to make orderBy ignore value 0 in eloquent laravel
我的問題是我的集合有一個 position 字段,我希望它按升序排序,但默認值為 null 或 0 的字段被檢測為小於具有索引的字段。 我的問題是如何讓 orderBy 忽略值 0 或 null。 ...
[英]Laravel - ORM query with dynamic fields
我有一個端點可以接收具有不同名稱和值的不同字段。 我可以用這種方式接聽 API 電話 endpoint.php?brand=1&car=3 endpoint.php?color=red&type=5 因為我不知道我會收到什么值,所以我想用我收到的參數進行查詢 這是我現在的查詢,但如 ...
[英]How to apply a Laravel Eloquent where() condition on both parent and child (hasMany() relationship)
我有一個名為EmailList的 Laravel Eloquent 模型和一個名為Subscriber的模型。 我在 EmailList 上定義了以下 hasMany 關系。 public function subscribers() { return $this->h ...
[英]Laravel Eloquent: API Resources - How does it work, so that I can create a similar class?
看這個例子: 這在內部如何運作? 因為乍一看我們只是返回一個UserResource類的UserResource 。 但是 Laravel 神奇地調用了toArray函數並正確解析了它。 我希望我的推薦課程也能正常工作。 和 輸出數組/json 應該解析為: ...
[英]How can check variables is null or empty with one function in laravel 8?
我想檢查 laravel 8 中是否有一個函數,比如IsNullOrEmpty for C#只使用一個函數來檢查空值和空值。 ...
[英]how to to make eloquent scope with whereHas like sql query below?
如何使 eloquent scope 與 whereHas like sql 查詢下面表屬性(id、title、slug、category_id、location_id、image) 表類別(id,名稱,slug) 表城市(id,名稱,slug) 我需要的簡單 sql 查詢 我想在Property ...
[英]how to format responses JSON with Relationship - Laravel/Eloquent
我正在開發一個 Laravel 項目,我想為一個網站創建一個 REST API。 在我的系統上,我有兩個表:我的表是 Item 和 Product 表,它們都具有一對一的關系我想要來自如下兩個表的 json 響應 但我得到的實際格式如下 我的項目 Controller class 我的項目資源 c ...
[英]WHERE EQUALS TO SUBQUERY SELECT
我只想知道如何將此查詢轉換為 laravel eloquent 查詢。 我已經完成了這部分,但只到了 where not IN。 任何幫助肯定會受到贊賞。 謝謝! ...
[英]Laravel Check for Value from Relation
我有一個看起來像這樣的查詢,我在其中獲取特定位置的各種企業的數據,並且我需要能夠判斷每個企業都有(或沒有)女性員工。 我的迷你資源如下所示: 這是示例響應的樣子: 我真的不需要人員數組,我只想檢查關系中是否存在女性,然后返回類似於以下內容: 有沒有 eloquent 方法來實現這一點? 注意:在我的 ...
[英]How to Solve Controller Error in Laravel6?
我收到AdminController錯誤,我無法解決這個問題。 我在網絡文件中使用命名空間。 請讓我知道我錯在哪里。 我的錯誤是這個.. 這是我的 web.php 文件 這是我的 AdminController.php 文件.. ...
[英]Laravel Eloquent API Resources: remove "data" key from response (collection)
我有UserResource API 資源UserResource 。 當我嘗試運行這樣的代碼時: 響應將是這樣的: 我如何刪除data鍵或重命名它以獲得類似此響應的內容? ...
[英]Modify response structure using Eloquent: API Resources
我是 Laravel 的新手。 我使用 laravel 作為 REST 端點,我使用 Eloquent: API Resources 將我的數據轉換為 JSON。 我正在使用 Collection 和 Resource 來解析來自我的查詢的數據。 所以下面是我的回復的結構: 現在我需要對數據進 ...
[英]How to remove some values in collection when using Laravel API Resource
我在一個博客項目中。 我的 Post 模型有這個 API 資源 但我不想在我收集帖子時得到'body' => $this->body ,因為我只在我想顯示帖子時使用它,而不是為了列出它們 我怎樣才能做到這一點 ? 我應該使用資源集合嗎? 更新: makeHidden應該可以工作,但 ...
[英]Return all relationship data in laravel
我想使用 eloquent model 檢索數據並在以下 json 響應中返回。 目前我正在接收用戶、交易和客戶數據,但我無法檢索客戶端屬性中的數據,例如 ubications[]、contactos[] 和 plan[]。所以我需要關於子屬性的幫助,因為我已經實現了關系. 這是我正在使用的模型用戶 ...
[英]How to alter data in relations field in laravel eloquent model after returning result?
我正在使用 Laravel 5.6。 並使用 Eloquent model 從數據庫中獲取數據。 在返回的結果集中,我發現“關系”字段為空。 但我需要改變這個帶有一些自定義數據的“關系”。 我該怎么做? 我返回的結果: 在圖片中,突出顯示的字段需要使用一些自定義數據進行更改。 ...
[英]What is the difference between a json resource & resource collection? in Laravel
有人可以解釋 ResourceCollection 和 JsonResource 之間的區別嗎? 在 Laravel 6 文檔中,您可以生成 2 種不同類型的資源... ResourceCollection 和 JsonResource。 https://laravel.com/docs/6.x ...
[英]Resource: Use whenPivotLoaded as condition
我想要這個: 一個集合在沒有 pivot 的情況下加載時返回'title' => $this->title 一個集合返回title => $this->pivot->title. "Hello World" 裝載 pivot 時的title => $this-&g ...