-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gravitano
committed
Nov 19, 2014
1 parent
19ea7b2
commit f066805
Showing
7 changed files
with
144 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php namespace Pingpong\Admin\Providers; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Illuminate\Support\Facades\Response; | ||
use Pingpong\Validator\Exceptions\ValidationException; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class ErrorServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $handlers = [ | ||
'NotFound', | ||
'FormValidation', | ||
'ModelNotFound', | ||
]; | ||
|
||
/** | ||
* Boot the provider. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->registerErrorHandlers(); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Register the required files. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerErrorHandlers() | ||
{ | ||
foreach ($this->handlers as $handler) | ||
{ | ||
$this->{'register' . $handler . 'Handler'}(); | ||
} | ||
} | ||
|
||
public function registerNotFoundHandler() | ||
{ | ||
$this->app->error(function (NotFoundHttpException $e) | ||
{ | ||
if ($this->app['request']->ajax()) | ||
{ | ||
return Response::json(['code' => 404, 'message' => 'Not Found'], 404); | ||
} | ||
|
||
return Response::view('404', [], 404); | ||
}); | ||
} | ||
|
||
public function registerFormValidationHandler() | ||
{ | ||
$this->app->error(function (ValidationException $e) | ||
{ | ||
if ($this->app['request']->ajax()) | ||
{ | ||
$errors = $e->getErrors()->toArray(); | ||
|
||
$default = ['status' => false]; | ||
|
||
return Response::json($default + compact('errors')); | ||
} | ||
|
||
return $this->app['redirect']->back()->withInput()->withErrors($e->getErrors()); | ||
}); | ||
} | ||
|
||
public function registerModelNotFoundHandler() | ||
{ | ||
$this->app->error(function (ModelNotFoundException $e) | ||
{ | ||
return Response::view('404', [], 404); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php namespace Pingpong\Admin\Validation\Category; | ||
|
||
use Pingpong\Validator\Validator; | ||
|
||
class Create extends Validator { | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required', | ||
'slug' => 'required|unique:categories,slug', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php namespace Pingpong\Admin\Validation\Category; | ||
|
||
use Pingpong\Validator\Validator; | ||
use Illuminate\Support\Facades\Request; | ||
|
||
class Update extends Validator { | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required', | ||
'slug' => 'required|unique:categories,slug,'. Request::segment(3), | ||
]; | ||
} | ||
} |