I have two models. Both of them are pivots because they join other tables. But also they have a relationship with themselves. I want to get all entities of CompanyUserProduct but with the additional column user_id from CompanyUser, so I can do pluck(‘user_id’) on the collection and get all IDs at once. Is it possible to do it in Eloquent,
Tag: laravel-7
How to use multiple whereBetween to sum two different record
I need to compare and sum data from two different date. Assuming i have 4 input dates Currently, my query only able to get one whereBetween date data as below Current Code Current result from startdate and enddate Example another result from compare_startdate and compare_enddate How to query another result from compare_startdate to compare_enddate in order to sum result of
Target class [view] does not exist. in Container.php
I have a problem with laravel and I don’t know how to fix it for now. Actually I don’t know how I face this problem, but will try to explain you what I did and what I tried for now to fix the problem. I tried composer update and this problem occured. Now I can not type any command like
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-values.php
How to access assets from resources sub folder in Laravel?
This is the javascript source in blade file. OR Both asset and URL::to doesn’t work. The actual file path is: resources -> views -> template -> js error shows 404 not found on local xampp server. its working fine in production. project is copy of production code. I would appreciate for your kind support. thanks Answer Static assets are usually
Convert a json to multi-dimensional PHP array
I have the following json sent to my API endpoint {“key”:”levels”,”value”:”[{role_id:1, access_level_id:3}, {role_id:2, access_level_id:1}, {role_id:3, access_level_id:2}]”,”description”:””} at the backend, I receive it as a Laravel request as follows: And it returns the following expected result array ( ‘key’ => ‘levels’, ‘value’ => ‘[{role_id:1, access_level_id:3}, {role_id:2, access_level_id:1}, {role_id:3, access_level_id:2}]’, ‘description’ => NULL, ) But I need to convert the ‘value’ to
Why laravel landing page route return MethodNotAllowedHttpException?
I’m using laravel 7.x. since function(){return view(welcome);} will produce an error when I run php artisan route:cache, so I write this code below to replace function(): Route::get(‘/’, ‘…
Laravel 7 migration error. Cannot add foreign key constraint
Try to create foreign key in Laravel 7 but when I migrate tables using artisan it gives error SQLSTATE[HY000]: General error: 3780 Referencing column ‘remote_id’ and referenced column ‘parent_id’ in …
Not found route in Laravel 7
Making a website on Laravel 7.28. Added a route to ‘routes/web.php’: The controller is created in ‘appHttpControllersLKIndexController.php’. It has a method: Created promoter file ‘resourcesviewslkindex.blade.php’. When I’m trying to follow the route http://127.0.0.1:8000/lk. I get an error: The requested resource /lk was not found on this server. If I change the ‘lk’ routes to the ‘account’, for example, then at
Get the id of the stored items after using Laravel insert eloquent
I stored an array in the database using the Laravel insert Eloquent method as below: $newTags = [ [ ‘name’ => ‘tag1’ ], [ ‘name’ => ‘tag2’ ], ]; if (sizeof($…