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: laravel
“Syntax error or access violation” error while trying to join a table column multiple times
I want to join 3 tables named members, students and baseinfos. And baseinfos holds some id as bas_id and name of it is stored in bas_value: And this is my code: But this is wrong and shows me this error: Note that I can not say this: Because degree.bas_value will overwrites gender.bas_value! So how can I join these 3 tables
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
How to test create model service?
I decided to create CreateClassroomService to separte logic in my controller method. I am trying to test this service as part of learning unit testing, but I don’t know how. I don’t know how to mock the classroom object to control what the method should return. Does this mean that creating this service was not a good idea because I
CSRF Token Mismatch with Laravel API using Digital Ocean Load Balancer with Sticky Session
I am working on a project in Laravel 8 which I am now testing the deployment on production servers. I have set up 2 Digital Ocean Droplets that are behind a load balancer with Sticky Sessions enabled. I am attempting to login via a SPA app with a separate Laravel API so the middleware is configured for the api routes
Sort By date in hasMany relation first record for Laravel project [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question I have a courses table and every course has many sessions, So I need to sort courses by the first session of the course date
Combine categories tree
I have an array like that: In these arrays first level and second level are the same, only the last level is different. I want to combine them into one array. I want to receive result like that: Answer
How to group PHP arrays by key before sorting by another key?
I have an array that contains the key counted and placement which I am trying to group by before I sort. The array should be first sorted by counted and then, for each duplicate counted, should then sort by placement. My expected output here would be: I have tried to usort to achieve this: But this gives me an unexpected
Laravel Mutator Database Value with Variable variables
I have the following Laravel Eloquent Mutator When calling $object->used_working_time i get the value stored in the database as expected. When using Variable variables $object->{‘used_’.$name} with $name = ‘working_time’ the $db value is null. Is there a way to get the database attribute with the second way. I am using Laravel 8.74 and PHP 8.0. Answer Try to create a
Laravel how to properly pass data to href
sorry if the question is kind of newbie. I am new to php and laravel, still trying to learn through tutorial. I am trying to pass the ‘No’ in my database to the url, so that the url when I clicked on Daftar, it will show http://127.0.0.1:8000/search/{No} Webpage designed I did try to put it this way in my href