Skip to content
Advertisement

Tag: laravel-5

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.

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

Advertisement