Skip to content

Commit

Permalink
⬆️ Support Laravel 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 21, 2018
1 parent fd9b8f0 commit 991849e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.*",
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*",
"jasongrimes/paginator": "^1.0",
"php": "~7.0"
},
Expand Down
39 changes: 27 additions & 12 deletions src/MetApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function paginate($collection,$perpage=15) {

}

protected function verify() {
protected function verify($abort=true) {

$validate = Validator::make($this->request->all(), $this->query['options']);

Expand All @@ -91,7 +91,11 @@ protected function verify() {
}
}

return false;
if ($abort) {
return $this->abort();
} else {
return false;
}

}

Expand Down Expand Up @@ -152,13 +156,20 @@ protected function addError($type,$message,$file=null,$line=null)
* returns $this->errors w/ no view, transformer and an error code of 500
*/

protected function error($key='unknown',$message='Unknown Error') {
protected function error($key='unknown') {

if ($key !== 'unknown' || count($this->errors) < 1) {
$this->addError($key, __($message));
$this->addError($key, __($key));
}

return $this->render(['errors' => $this->errors], false, false, 500);
$this->render(['errors' => $this->errors], false, 500);
}

/**
* render errors and abort
*/
protected function abort() {
$this->render(['errors' => $this->errors], false, 500, true);
}

/**
Expand All @@ -177,7 +188,7 @@ protected function success($message='Successful')
* @param integer $code response code, defaulting to 200
* @return \Illuminate\Http\Response
*/
protected function render($data=false,$code=200) {
protected function render($data=false,$code=200,$abort=false) {

if ($code === 403 || count($this->errors) > 0) {
$response = $data;
Expand All @@ -191,17 +202,21 @@ protected function render($data=false,$code=200) {
if ($this->request->query('callback') !== null) {
$json = json_encode($response, JSON_PRETTY_PRINT);
$response = ['callback' => $this->request->query('callback'),'json' => $json];
return response(view('metapi::jsonp', $response), 200)->header('Content-type', 'text/javascript');
}

if (
$responsable = response(view('metapi::jsonp', $response), 200)->header('Content-type', 'text/javascript');
} else if (
strpos($this->request->header('accept'),'text/html') !== false &&
config('app.debug') === true && $this->request->query('json') !== 'true')
{
return response(view('metapi::json', ['json' => json_encode($response, JSON_PRETTY_PRINT)]), $code);
$responsable = response(view('metapi::json', ['json' => json_encode($response, JSON_PRETTY_PRINT)]), $code);
} else {
$responsable = response()->json($response, $code, [], JSON_PRETTY_PRINT);
}

if ($abort) {
return abort($responsable);
}

return response()->json($response, $code, [], JSON_PRETTY_PRINT);
return $responsable;

}

Expand Down

0 comments on commit 991849e

Please sign in to comment.