33 lines
786 B
PHP
33 lines
786 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Externo;
|
|
|
|
use App\Exceptions\Externo\WithoutPermissionException;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
|
|
abstract class Controller extends BaseController
|
|
{
|
|
protected $controller;
|
|
protected $permissaoId;
|
|
|
|
protected function auth($method)
|
|
{
|
|
if (is_null($this->permissaoId) || !auth()->user()->permissoes()->where('id', $this->permissaoId)->exists()) {
|
|
|
|
throw new WithoutPermissionException();
|
|
}
|
|
|
|
$this->saveLog($method);
|
|
}
|
|
|
|
private function saveLog($method)
|
|
{
|
|
auth()->user()->logsAcessos()->create([
|
|
'controlador' => $this->controller,
|
|
'metodo' => $method,
|
|
'acessado_em' => Carbon::now(),
|
|
]);
|
|
}
|
|
}
|