Skip to content

Updated README. Formatted. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@ This package will use laravel passport [https://laravel.com/docs/5.6/passport]

## Installation

1 - Add this package in your project.
2 - Now add the trait CanHaveAPIEndPoints in the controller who will contribute in the mobile service. You can also add this trait in the base controller and use it. Now you can use **returnFormattedResponse** method to send the respose. This function will check the request and send the reponse accordingly.
1. Add this package in your project.
```sh
composer require coloredcow/laravel-mobile-api
```

IF first argument is an array and second argument is a string then for web return the html repose for that view and data.
2. Now add the trait `CanHaveAPIEndPoints` in the controller who will contribute in the mobile service. You can also add this trait in the base controller and use it. Now you can use **returnFormattedResponse** method to send the response. This function will check the request and send the reponse accordingly.

```
If first argument is an array and second argument is a string then for web return the html repose for that view and data.

```php
return $this->returnFormattedResponse(['projects' => $projects], 'project.index');

```

IF you want to send custom respose for both API and web then you can pass the closures also.
If you want to send custom respose for both API and web then you can pass the closures also.

```
return $this->returnFormattedResponse(
function (){
.... // for api
},
function (){
... // for web
}
);
```php
return $this->returnFormattedResponse(
function (){
// for api
},

function (){
// for web
}
);
```

## Excaption Handling
## Exception Handling

For clear error responses you need to add the trait in the **App\Exceptions\Handler** class and add the following code snippt in report method.

```
```php
public function render($request, Exception $exception)
{
if($this->isApi()) {
Expand All @@ -52,13 +56,16 @@ For clear error responses you need to add the trait in the **App\Exceptions\Hand

If you want to set the auth user for every authenticated route then add RestApiMiddleware in your project and apply in on routes.

```
In kernel.php

'restapi' => ColoredCow\LaravelMobileAPI\RestAPIMiddleware::class,
```php
'restapi' => [
\ColoredCow\LaravelMobileAPI\RestAPIMiddleware::class,
]
```

In routes file

Route::group(['middleware' => ['auth:api', 'restapi:auth'] ], function () ...

```php
Route::middleware(['auth:api', 'restapi:auth'], function(){
// routes
});
```