public function __construct($message = null, $action = null, $subject = null, $code = 0, \Exception $previous = null) { $this->action = $action; $this->subject = $subject; $this->defaultMessage = ac_trans("messages.unauthorized.default"); $this->message = $message ?: $this->defaultMessage; parent::__construct($this->message, $code, $previous); }
public function testAcTrans() { $defaultErrorMessage = ac_trans("messages.unauthorized.default"); $this->assertEquals('You are not authorized to access this page.', $defaultErrorMessage); App::setLocale('fr'); $defaultErrorMessageFr = ac_trans("messages.unauthorized.default"); $this->assertNotEquals('You are not authorized to access this page.', $defaultErrorMessageFr); $this->assertEquals("Vous n'êtes pas autorisé à accéder à cette page.", $defaultErrorMessageFr); }
public function getUnauthorizedMessage($action, $subject) { $keys = $this->getUnauthorizedMessageKeys($action, $subject); $variables = ['action' => $action]; $variables['subject'] = class_exists($subject) ? $subject : snake_case($subject, ' '); $transKey = null; foreach ($keys as $key) { if (\Lang::has('messages.unauthorized.' . $key)) { $transKey = "messages.unauthorized." . $key; break; } } $message = ac_trans($transKey, $variables); return $message ?: null; }