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
Tag: laravel
find() does not get the existing row
I have a resource Controller with this index method like this: But it returns this error: Trying to get property ‘slug’ of non-object And when I dd(Category::find(25), Category::find(24), Category::find(23), Category::find(22)); I get NULL results. Meaning that it can not find data with specified ids. However there are 25 records stored at the categories table: So what is going wrong here?
Cannot union two Joints Laravel
Im trying to union 2 joins, but im getting weird error… I have “Clientes” -> means clients, and i got all the clients that they got registered in orders and news. In news table i got the cliente_id -> client_id , And in orders, i got the same, cliente_id -> client_id, In news i got x clients, and in orders
Laravel – how to copy collection to a new variable
I wanted to change my collection set to a new variable, but it changed the original. I thought this was a JavaScript issue and PHP was referring to value. How do I set my collection to a new variable, which I can alter without changing the original collection. I’m using this workaround for now: Answer Try using clone If you
Datatable Action Custom Delete Confirmation not working
Actually am trying to implement custom actions buttons (In my case using a tag) in my datatable. here i want when user click on delete link then i want a confirm box saying “Are you sure” or something like that. Now Here when i click on delete link then it is working fine But when i pass any string in
How can I access variables displayed with dd( ) of Laravel?
I need to access to this id here is the code I used to displayed with dd() What I need is to get the variable I mentioned in the picture below, so I can delete the uploaded file with its own id so far I tried : but it doens’t work, it gives me this Error What should I do
Laravel Livewire error “must not be accessed before initialization”
I try to using Livewire Binding Directly To Model Properties, and i get this error, Anyone help please ? Thank in advance. Typed property AppHttpLivewireV2SettingsLocations::$country must not be accessed before initialization Answer When you define the type of a variable in PHP, you need to provide it a default value. If your component is creating a Country, you can set
Laravel API Resourse returning relation only on ‘collection’ method
guys I’m new to Laravel. I currently building an API, and I have a couple of endpoints (the one that we will discuss are the Get All Tasks and Get Single Task) The problem is that whenever I call the Get All Tasks endpoint it returns me the task resource + the user resource there. However when I call the
Loop through this multidimensional array and display as a list of items in Laravel Blade
I have the following array. I need to show first_names relevant to each team_name as a list. As this way. Below is my code block in blade.php but it gives me the error ‘Trying to get property ‘team_name’ of non-object’. I tried several methods but was failed to create the loop. This is my controller function if it is useful
check in blade if exists variable in @include
I´m developping a system with laravel 7.4 and i need check if one variable that i´m sending from my controller exists in my blade. If exists, include it: I have this code in my controller: this return profile image or system image but it´s possible that this images don´t exists and i need check before, because i have error in