Standardized message responses for REST resources
Rest Messages is a lightweight package designed to standardize success messages across your Laravel REST API. It automatically detects the model name and the current CRUD action (index, store, update, destroy) to generate localized and professional response messages.
- Consistency: Ensure every success response in your API follows the same linguistic pattern.
- Automatic Detection: No need to manually type messages for every controller action. The package "just knows" what you're doing.
- Localized: Built-in support for multiple languages with proper grammar and gender resolution for model names.
- Clean API: Focus on your data, while the package handles the communication part of your REST interface.
We invest a lot of resources into creating best in class open source packages. You can support us by sponsoring us on GitHub.
You can install the package via composer:
composer require victormgomes/rest-messagesSimply use the HasResourceMessages trait in your response helpers or base controllers.
use Victormgomes\RestMessages\Traits\HasResourceMessages;
class ApiResponse
{
use HasResourceMessages;
public function success($data)
{
return response()->json([
'message' => $this->message(),
'data' => $data,
]);
}
}The $this->message() method will automatically resolve the model and action from the current route context. For example, if called from UserController@store, it will return: "User created successfully."
composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.