Questions tagged [laravel-eloquent-resource]

35 questions
0
votes
0 answers

Listing Nested Resources in Filament Admin

I'm working with Laravel, Filament Admin panel, and staudenmeir/laravel-adjacency-list. I'm struggling to bring this nested tree structure into the CategoryResource List table through getEloquentQuery() properly. I have a resource (Categories) which…
0
votes
2 answers

How can i add new colum in existing table as a foreign in laravel 9

I was trying to add a new column as a foriegn key in existing table in laravel 9. But, it continuously giving SQL error. I want to create a simple category_id as a foreign_key in brand table. The below code doesn't…
0
votes
0 answers

Model extends Authenticatable and does not retrieve data from users table

in my Laravel 9 project, the model does not retrieve users' data from the table, probably because it extends authenticatable instead of Model. and when I changed that, the authentication did not work. Here is my model:
0
votes
2 answers

How to combine multiple WHERE condidtions in WITH and WHEREHAS in Laravel Eloquent query

In below query the awarded, banned, featured and published parts are being ignored, why? Query: Show me a list of all featured published books with an author that has been awarded and has not been banned. $books = myBooks::with('authors') …
bart
  • 14,958
  • 21
  • 75
  • 105
0
votes
2 answers

how to make orderBy ignore value 0 in eloquent laravel

My problem is that I have my collection that has a position field and I want it to be sorted in ascending order, but the fields that have the value null or 0 by default are detected as smaller than those that have an index. My question is how can I…
0
votes
1 answer

Laravel - ORM query with dynamic fields

I have an endpoint that can receive different fields with different names and values. I can receive an API call in this way as in this other endpoint.php?brand=1&car=3 endpoint.php?color=red&type=5 Since I don't know what values ​​I will receive, I…
0
votes
1 answer

Format result for requesting all data

I have my controller with index() and show(). { /** * Display a listing of the resource. * * @return \App\Http\Resources\MyRessource */ public function index() { //??? } /** * Display the…
Franck
  • 3
  • 3
0
votes
1 answer

How to apply a Laravel Eloquent where() condition on both parent and child (hasMany() relationship)

I have a Laravel Eloquent Model called EmailList and a model called Subscriber. I defined the following hasMany relationship on the EmailList. public function subscribers() { return $this->hasMany(Subscriber::class); } This…
0
votes
1 answer

How can check variables is null or empty with one function in laravel 8?

I want to check if there is a function in laravel 8 like IsNullOrEmpty for C# to check for empty and null value using just one function.
Jon
  • 57
  • 3
  • 11
0
votes
1 answer

how to to make eloquent scope with whereHas like sql query below?

how to to make eloquent scope with whereHas like sql query below table Property(id, title, slug, category_id, location_id,image) table Category(id, name, slug) table City ( id, name, slug) The simple sql query that i need Select * from property…
0
votes
1 answer

how to format responses JSON with Relationship - Laravel/Eloquent

I'm working on a Laravel project and I want to create a REST API for a website. On my system, I have two tables: my tables are Item and Product table which both have one to one relationship i want the json response from two tables like below "data":…
Khal
  • 219
  • 5
  • 19
0
votes
2 answers

Laravel Check for Value from Relation

I have a query that looks like this where I fetch data for various businesses in a particular location and I need to be able to tell that each business has (or does not have) a female employee. $business = Business::where('location', $location) …
0
votes
1 answer

How to Solve Controller Error in Laravel6?

I am getting AdminController error, and i am unable to solve this. I am using namespace in web files. Please let me know where i am mistaking. My error is this.. Target class [App\Http\Controllers\Admin\AdminController] does not exist. Here are my…
saini tor
  • 223
  • 6
  • 21
0
votes
2 answers

Resource: Use whenPivotLoaded as condition

I would like to have this: A collection returns 'title' => $this->title when it's loaded without a pivot A collection returns title => $this->pivot->title . "Hello World" when it's loaded with pivot. This is my approach: namespace…
0
votes
1 answer

Is it correct to create different Api Resources for each request?

Will it be correct, if I create API RESOURCES for each request. And how to make a connection between three tables in Resources. For example: class UserResource public function toArray($request) { return [ 'id'=>$this->id, …