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.
Tag: laravel-5
Laravel Multiple Sortby Not Working Properly
i have some issues with laravel sortBy ( laravel 5.4 ) .. based on what i read on many websites, it says that for doing multiple sortBy laravel was by using reverse order.. so i try to do that.. but still not working properly.. So here it is.. I have this collection of object… My Goal is to have this
Blade – Print variable into variable
I am trying to print a variable into another variable in a blade template. I have a variable from database that contains “dynamic” data from another variable. Example: $foo = ‘user’; $bar = ‘Hello {{…
Laravel Sum Eloquent sum of multiple multiplications from two different tables
Currently, in my Laravel project controller, I am using one query QUERY 1 public function cartreview(Request $request,$sp_id, $service_id,$cart_id) { $total = DB::table(‘pricings’) ->…
Defining custom namespaces on routes in laravel 5.6
So Consider the following: This explodes when I hit any of these routes because: Is there not a way in laravel 5.6 to say: No I don’t want to use AppHttpControllers I want to use the namespace I specified? Answer Try with a slash ->namespace(‘AppModulesConfigControllers’)
Combine validation errors and return one single message
I have two arrays I want to validate in my custom Request: This returns an error message per each word. But I want a single general message like “Some of the words are invalid”. Is there any Laravel-way to do this? Answer You could do this: EDIT: I think I may have found a solution: First, make sure you import
“405 Method not allowed” in Laravel 5.6.14
I am just learning laravel resource methods to build a basic API. Below is the code of my api.php file that shows all the API routes. This works perfectly on get and delete methods. But for Post method, it is throwing error “405 Method not allowed”. I am using Postman to test the API calls. To be specific, below is
Laravel Storage file encoding
I’m trying to save text file as UTF-8 by using Laravel’s Storage facade. Unfortunately couldn’t find a way and it saves as us-ascii. How can I save as UTF-8? Currently I’m using following code to …
Laravel Queue How to get data in job handle method
I have created a sequence of messsages to be sent in text messages through twilio. I have created a controller to put the messages in a queue with the data received in the post request. Here is my controller to make queue: And in handle the job , in the handle function } I am not able to figure out
Migrations in Laravel 5.5: Cannot declare class because the name is already in use
While running a migration in Laravel I got an error: PHP Fatal error: Cannot declare class UpdateEnquiriesTable, because the name is already in use in /var/www/project/database/migrations/2018_01_17_160335_update_enquiries_table.php on line 33 Having done a bit of research, I see that each migration file needs a unique class name (I don’t remember mention of that before, but that could be me). According to