blue-twilight/app/Http/Controllers/Controller.php

41 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected function authorizeAccessToAdminPanel()
{
// A user can access the admin panel if they are either an administrator, or are allowed to create albums
// Further checks within the admin panel determine what a user can do within the panel
if (!Auth::user()->can('admin-access') && !Auth::user()->can('admin-create-albums'))
{
App::abort(403);
}
}
/**
* Gets either the authenticated user, or a user object representing the anonymous user.
* @return User
*/
protected function getUser()
{
$user = Auth::user();
return (is_null($user)
? User::anonymous()
: $user);
}
}