https://github.com/mlk9/dual-response
With this package, you can operate your API and web in a single controller. (Laravel Package)
https://github.com/mlk9/dual-response
api-rest controllers laravel laravel-package
Last synced: about 2 months ago
JSON representation
With this package, you can operate your API and web in a single controller. (Laravel Package)
- Host: GitHub
- URL: https://github.com/mlk9/dual-response
- Owner: mlk9
- License: mit
- Created: 2022-03-11T03:48:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-02T17:03:40.000Z (over 3 years ago)
- Last Synced: 2026-01-14T13:54:33.368Z (about 2 months ago)
- Topics: api-rest, controllers, laravel, laravel-package
- Language: PHP
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Dual Response
With this package, you can operate your API and web in a single controller. (Laravel 6>=)
--
با این پکیج می توانید پاسخ های متفاوتی هنگامی که در روت api یا web می فرستید دریافت کنید.
# Installation via composer
```sh
$ composer require mlk9/dual-response
```
then publish vendor
```sh
$ php artisan vendor:publish --tag=dual-response
```
# Documents
## Example for usage
response($webRoute //your response, $apiRoute //your json response)
BookController.php
```sh
use Mlk9\DualResponse\Facades\DualRes;
...
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$books = Book::paginate(40);
return DualRes::response(view('book.index',compact('books')),['data' => $books]);
}
```
You can change default values with pass array
## Default Response Api
```sh
'status_result' => true,
'status_code' => 200,
'message' => __('dualres.request_successful'),
'errors' => null, //removes when don't have any errors
'data' => null, //removes when don't have any data
'current_time' => now()->timestamp,
```
## Default Response When you pass to key `error`
In api routes :
```sh
'status_result' => false,
'status_code' => 400,
'message' => __('dualres.request_not_valid'),
'errors' => [//your errors],
'current_time' => now()->timestamp,
```
In web routes return your response.
## Default Response When you pass to key `data`
In api routes :
```sh
'status_result' => true,
'status_code' => 200,
'message' => __('dualres.request_successful'),
'data' => [//your data],
'current_time' => now()->timestamp,
```
In web routes return your response.
## Default Response When you pass null to key `data` (not found - 404)
In api routes :
```sh
'status_result' => false,
'status_code' => 404,
'message' => __('dualres.not_found'),
'current_time' => now()->timestamp,
```
In web routes abort 404 error.