I have a Prize, Ticket and User model. A prize can have many tickets, and a ticket can only be associated to one User. Each Prize will have one Winning Ticket, what I am trying to do is list all my Users that have a winning Ticket like so: $winning_tickets returns an array of winning ticket ids, but the $users
Tag: eloquent
Laravel: Querying JSON column containing array, expecting similar results to “whereIn”
I have a database column called support_tags. This is a jsonb column containing a simple array that looks like: I am attempting to query this column using the following: This doesn’t retrieve the results I am hoping for/expecting. If I send the following array: The results I get back are services that contain all array elements. I need this to
I am fetching data of user where role equals to teacher , status is active and other orWhere. This collection gives me super admin user also but why?
I am working on search. I am facing issue with the query. when ever i search super. It gives me super admin user also but i am using ->whereRelation(‘role’,’name’, ‘teacher’) Answer that because if any orWhere come with true, the record will be fetched, you should group your orWhere in one statment:
Select DISTINCT returns duplicates data Laravel 8
I’m trying to get groups that belong to a supervisor to be displayed for him. And I’m using join to get each gpid information base on supervisor_id, query its okay but returns duplicate data of the last row. I can’t figure out why it is duplicating the last record. Any help would be much appreciated. Result Answer You can try
Laravel Eloquent the same queries
I’ve faced this question on the interview recently. How many objects will be created? How many db queries will be executed? I’ll be thankful so much for any detailed explanation Answer In Either one of the code above, the query will just be 1 $a = Flight::find(1); is same as Since $a & $b are 2 different variables, though they
laravel id value changed after adding a nested loop
I used the following code to display the role of the user however, when I want to edit or delete it leads me to the deleted ids number 2/3 it return the same thing even when I change the for else with foreach Attempt to read property “id” on null (View: C:laravelgautoresourcesviewsdashboarduseredit.blade.php)! when I delete the nested foreach loop everything
Laravel Eloquent return conditionally when first condition not exists return another
i use Eloquent for get Multilanguage post title. this return english title, but some times the english title not exist so i want to return title in another language . i mean when use getTitle_en to get engish title ([‘cat’ => ‘title’, ‘meta_name’ => ‘en’]) , if it’s not exist return title in another language like “nl” and again if
How to get result from database based on the user with laravel
I started coding laravel and everything was fine till I wanted to get the result based on the user, how to do it, what do I need to do?. Answer You can use where clause. Suppose you wanna fetch all the blogs of a user. like: Or create a relation in User model Then
laravel – unable to get data outside foreach
dump($data) outside the foreach loop gives me only 1 data where as dump($data) inside the foreach shows all arrays of rows of data . How can i get all rows of data outside the foreach too? EDIT: Error: Call to a member function paginate() on array Answer In Controller add new function for it After that crate that function for
How to get user order data by specific month in laravel?
I want to user orders data by specific month in a year. Here is my order Table id | user_id | price | quantity | total Here is my order model Here is my user model In a controller, by doing this I get all user orders Now, How can I get specific month user orders detail? I want to