image address has location and total number of users. this query will return all the users and on relation whose query did not match will be null .I want to pull only those users which do not null value on relation and order By accordingly. Answer You can use whereHas condition
Tag: laravel-5
When I pass string variables to controller in laravel via ajax, It doesn’t show me proper data
This is my Ajax Query This is y Controller And this is the response I get, butI actually want the proper string value that I passed through ajax Answer actually, your script shows proper data what you asking for here your URL looks something like this. because you sending a string instead of a value what you need to do
Is mass assignment protection needed when properly using validation?
I’ve been using Laravel (5.4) and PHP both for the very first time in a legacy app I’ve been tasked to maintain, and over the past couple of months I have noticed a pain point, which is mass assignment. I believe I have a well-enough grasp of what is is, but I am not sure if I am really utilizing
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
Route isn’t redirecting me to the correct page. It just shows me the same page but the url changes
I’ve made a blog template but I having trouble making the routes. When I click on the link, it should redirect me to the article page. Instead it just redirects me to the same page/same exact location. Here’s my code: BlogController : Routes : The routes that supposed to be redirecting me to another page is the 2nd one with
Allow only numeric and float values with validation in Laravel
I have a field days in my model, now I want to only save integer or float values in this column. Values can be like: 1 2 0.5 2.5 I tried to use numeric but then it is not allowing me to input float values: Any help is highly appreciated. Thanks Answer You can try custom validation rules for your
Import CSV data using Laravel
I’m trying to walk through as CSV file and extract all its contents. After the contents are imported I need to insert them into my mysql database table but before I can do that I need to check if these records exist. If a record does not, import this register. I’ve got headers and all content and I had created
Relationship eloquent in laravel?
In user: In post: I handle in controller: Then I get an array and the result returned is exactly what I need. But when I query this way because I need to get a lot of data, the result is an empty array. What did I do wrong? In UserController.php: Please give me any comments. Answer You have to select
Laravel Eloquent how to get relationship self object?
I have tables with below relationship And my HousingAdvertisement model has and HousingAdNearPlace when I make query like this: I got HousingAdNearPlace object in HousingAdvertisement model: How can I got self NearPlace model like this: Answer You need “Has Many Through” relationship on HousingAdvertisement And also define id keys as in ducumentation: https://laravel.com/docs/8.x/eloquent-relationships#has-many-through-key-conventions
Transform nested collection in laravel
I have a nested collection that I want to transform, pulling some keys “up a level” and discarding some other keys. Every item in the collection has an allergens property. I need to make each items allergens property, look like I’ve tried the following: But it doesn’t overwrite the allergens property Answer Since you’re posting your collection as JSON, I