I would like to find out how long an event lasted without having to add a finish time to that event. To demonstrate I have created a simple exercise: events table: I am currently pulling the data out of the database with: which returns the following: I would like to take the start time for the next event and use
Tag: eloquent
How to display all nested relations in a eloquent model referencing itself in many to many?
I have a many to many relation in Partners model that is referencing itself. The pivot table partner_owners has owner_id, owned_id, percent So a partner can own another partner and so on. How can I query all the nested relations for a partner without knowing how many levels are there? For example $partner = Partner::where(‘id’, 1)->get(); if this partner is
Undefined index , Unable to fetch columns- Laravel
In the above code, Notifications is the model Name. Getting the error Undefined index: notificationTypeName when trying to access column notificationTypeName of the array $data. dd($data) gives an ouput as below: Answer The all method returns the underlying array represented by the collection: see this : https://laravel.com/docs/8.x/collections#method-all so try with this: with foreach
Select specific column from morph relation according to type in Laravel
I am trying to write a query that selects columns from a model then selects some columns from a morph relationship table. But I have no idea to select columns, and relation tables have different columns. So some column has no slug, some have. Models How can I select specific columns from morph relation with checking morph type? I am
Laravel migration shows column doesn’t exist for existing columns
I’ve written the above code in the up method of my migration but when running migrate command, it shows – Course table migration file I don’t have any idea why this error occurs because i’ve the userId column in my ‘course` table migration. Any help is much appreciated. EDIT Output: View Query Model Controller Answer Problem A. “column course.userid does
Laravel 8 pagination Error – Column ‘is_deleted’ in where clause is ambiguous
I am new to Laravel and have stumbled upon a problem. Would you mind advising the right way of doing it if I am doing it incorrectly? For example, I have 3 tables: product, product_category, product_image, as below. Question 1 I am paginating my data on the frontend, but I am getting the following error with the below code. Column
Use explode on array?
What’s the easiest way to turn the array into Is there something built-in with laravel/collections that I can use? I know I can make a foreach loop and use explode and populate a new array, but I’m wondering if there is a built-in function in PHP or a laravel collections method I can use. Answer I think you’re looking for
Class not found laravel 8 only on production
Hello I’m new to Laravel and Eloquent, all I found about this problems it that it can by Case sensitivity problems but I can’t find any case problems. :Error message Class “AppModelsTvEpisode” not found I’m trying to get UserTvEpisode list to view it works fine in localhost (using Windows), but not on production server in throws an error that the
Update() in Laravel does not seem to be working
I’m working with Laravel 5.8 to develop my project and I have this table which shows some data from the DB: As you can see there’s a link named Edit for editing these data, so when someone clicks on that, this method runs: I have also added this form for updating the data sent to the edit.blade.php: And here is
How to mock Eloquent Model in Laravel 8 when calling a route in PHPUnit
I’m trying to mock a method in the Model so that I am able to test the controller api endpoint with different scenarios. I am currently using Laravel 8 with PhpUnit and Mockery package. In the route I am using Route model binding. api.php ProjectController.php ProjectControllerTest.php I am currently getting this error I have tried other options like makePartial() instead,