So I have two models User and File, these are connected with a one-to-many relationship. I have sorted the API routes and controllers to index all users, show specific user and index all files uploaded by that specific user. I do not know how to write the logic that will allow this route 127.0.0.1:8001/api/2/…
Tag: laravel
Laravel sync users to all of categoires which they can be unlimited
In our web application each user can create multiple nested category by selecting the parent which that specified with category_id column. now you supposed one of our user created this category structure: multiple nested categories children are unlimited, that means every category can be have child and we can…
Laravel AUTH() – Adding additional users (without registration)
I’ve tried to find information on this and can’t find any. I have a Laravel 7 application and have used the Laravel AUTH scaffolding for login/registration/authentication. I would like to allow a …
Laravel: How to separate array from query result into variables?
I have something like this: How to separate the ‘column’ and ‘count’ into variables? Answer Use native PHP functions; array_keys and array_values. For more details, read the below links; https://www.php.net/manual/en/function.array-keys.php https://www.php.net/manual/en/function.array-…
How to get all data from a Eloquent Model with it’s relations?
My question is how to get the data from an eloquent model with its relation? Imagine 3 tables: users: companies: addresses: And the relations: Company.php User.php Address.php In this case how I can get let’s say all the companies with their related users and addresses? on Company::whereHas(‘users…
Get most favorited (many to many) records in laravel
I have an app where users can favorite venues, this is done via a many to many relationship with a “favorites” pivot table. Now I want to retrieve the top 10 most times favorited Venues with …
Running migration from old branch in Laravel
I have a migration file in a Laravel project that sits on a slightly-older branch. In newer branches, newer migrations have been created and ran in production. I have ran the migration in my local …
How to get all the people in table 1 without getting the people who have me as parent_id in table 2?
I’m writing this post because I have a problem with my relationships on Laravel. Here is the structure I currently have: 1st table: – id – name – … 2nd table : – parent_id – child_id knowing that …
How to use an Interface Repository in a Laravel Nova Action?
I’m using the Laravel Repository Pattern to manage my resources and I was wondering how can I use an interface inside a Nova Action? Since an Interface cannot be instanciated, I was wondering how I could use my Interfaces within my action? In my Controller constructor I create my repository and then I&#…
Laravel 8: Undefined offset error message
I’m working with Laravel Controllers: When I fill the form that comes with this Controller I get this message: ErrorException Undefined offset: 300 From this line: So what is the problem here? Answer The problem is probably this line: $image[$size] = $imagePath . “{$size}” . $filename; it sh…