Skip to content

Tag: laravel

Sum price of one to many relation ship (laravel)

i have problem with one to many relation ship! So im try to sum product prices so here is what i mean: Model: Product.php Model: Orders.php So i want make smth like this: $var->product->price->sum(); My database if it needed: Orders: id product_id|user_id| |-|———-|——-| |…

In Macroable.php line 96: Method body does not exist

I’m fairy new to Laravel. I have created a migration file named: create_notes_table and when running command php artisan migrate this error message pops up. my create_notes_table file content Answer As the error message states there is no body() method in migrations. https://laravel.com/docs/8.x/migrati…

Laravel 5.6 aws cloudwatch log

Upgraded laravel from 5.4 to 5.6. Laravel removed $app->configureMonologUsing since version 5.6 the tutorial from aws not applicable anymore. https://aws.amazon.com/tw/blogs/developer/php-application-logging-with-amazon-cloudwatch-logs-and-monolog/ anyone can advise me where to migrate the logic inside $ap…

Laravel storage link won’t work on production

I’m using storage_path to save my images and I symbolic my storage folder to public_html On the local everything works fine, when I upload an image it will upload in storage folder and link of it will appear in public folder but since I moved to live host and production mode my images will upload in sto…

Accessor for relation objects in Laravel

this is my Category model: and when i call it in route for get all object like this: it seems accessor not work and i can’t get ‘Foo’ in category’s media object Answer You can use withDefault(): When there is no result, it returns a Media instance with the given attributes.