In my database I have to save people and the data of people that have a relationship with the first. For example: father, mother, son, daughter, etc Then the design of the database, I did it in the following way Is a relation many-to-many because, a person have many people related to it. But I’m not sure if is ok..
Tag: eloquent
Pulling all categories and grouping them by parent id
I am working with Laravel data querying and I need a query that is going to group all the children of a parent when I take the categories. the categories table has a name and a parent_id, the routes of the categories have the parent_id set as null, the query should return every category grouped by parent id and the
Show post comments with relationship – Laravel
Hi I am new to Laravel and I and trying to create a relationship bewteen my posts and post comments. I want to show all comments on a post with the same post_id as the posts id. I think it should …
fetch related records between 3 model
I have few products in 3 category (for example), and each product has a brand. I want to show brands which related to products in a specific category. Models: –product –brand –category relations: category has many products brand has many products How can I do that? Answer Considering you have 3 models with relationships like : Brand Model : Product
PHP Laravel – Eloquent is returning boolean fields randomly sometimes as 0 1 and others as true false when calling the method json
I am using Laravel Eloquent to write a REST API. When calling json from response() to return the object, boolean fields are returned as 0/1 sometimes and as false/true others. I would like to unify the format and make it all as 0,1 or as false,true instead of it being random here is the code sample: this return 0,1 and
How to get plain text from html in laravel model?
I’ve a database column named description in which i’ve saved input from tinymce editor. data is something like this, I can easily display the data in view with following, But, I need some processing to get 30 words from text with following code in model, and I’m currently geting empty when I call shortDescription function. Is there any way to
Laravel – convert array into eloquent collection
I need to use data from an API. I create a function: and dd($vouchers) return me: Now when I try to use $vouchers array with blade engine like: I got error: How I can convert array into eloquent collection. I use the latest Laravel 5.7 version Answer Actually your $vouchers is an array of arrays, So you may want to
Laravel 5.5 BelongsToMany with pivot conditions
I have three models, Clinic, Department and ClinicDepartment and has belongsToMany relation called departments from Clinic to Department using ClinicDepartment’s table as pivot table, but when i using this relation, scopes from ClinicDepartment not aplying in query. I decided to make Pivot model calling ClinicDepartmentPivotand apply those scopes to Pivot, but no luck. Clinic model: Department Model: ClinicDepartmentPivot Model: ActiveOnlyScope:
Eloquent Delete – SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value:
I am getting this error: When trying to delete records through a relationship, using: The raw query shows as: I have searched and searched but cannot find anything specific to this other than it may be something to do with a cast error. Maybe something to do with UUID’s? Migrations as follows: Answer I know it’s several months old, but
Laravel Nova Self-referential Relationship
In Laravel, if I want to create a self-referential relationship I can do the following: How can I make a Laravel Nova resource display this connection? Answer You can achieve what you want like this: This will allow to choose a parent post when you create or update a post. When you are in the detail page of a post,