Initial Commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of exception types with their corresponding custom log levels.
|
||||
*
|
||||
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
|
||||
*/
|
||||
protected $levels = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array<int, class-string<\Throwable>>
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\LogAction;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Logger
|
||||
{
|
||||
public static function LogCreated(int $loggable_id, string $loggable_type,int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'created'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogEdited(int $loggable_id, string $loggable_type,string $logMessage, int $amount = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'edited'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogDeleted(int $loggable_id, string $loggable_type,int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'deleted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogForceDeleted(int $loggable_id, string $loggable_type, string $logMessage = Null,int $amount = Null,int $target = Null,): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'force_deleted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogRestored(int $loggable_id, string $loggable_type, int $amount = Null, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'restored'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogLent(int $loggable_id, string $loggable_type,int $amount, int $target,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'lent'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogReturn(int $loggable_id, string $loggable_type,int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'returned'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogSetup(int $loggable_id, string $loggable_type,int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'set up'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogPickup(int $loggable_id, string $loggable_type, int $amount, int $target = Null,string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'picked up'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAdjusted(int $loggable_id, string $loggable_type,string $logMessage, int $amount = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'adjusted'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAmountAdded(int $loggable_id, string $loggable_type,int $amount,string $logMessage = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'amount_added'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogAmountRemoved(int $loggable_id, string $loggable_type,int $amount,string $logMessage = Null, int $target = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'amount_removed'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogReserved(int $loggable_id, string $loggable_type,int $amount, int $target, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'reserved'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
public static function LogValidated(int $loggable_id, string $loggable_type, int $target,int $amount = Null, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'validated'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
|
||||
public static function LogCancelled(int $loggable_id, string $loggable_type, int $target,int $amount = Null, string $logMessage = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'cancelled'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
|
||||
|
||||
public static function LogNote(int $loggable_id, string $loggable_type, int $target,string $logMessage, int $amount = Null): void
|
||||
{
|
||||
$log = new Log();
|
||||
$log->user()->associate(Auth::id());
|
||||
$log->action()->associate(LogAction::firstWhere('name', '=', 'note'));
|
||||
$log->loggable_type = $loggable_type;
|
||||
$log->loggable_id = $loggable_id;
|
||||
$log->target_id = $target;
|
||||
$log->amount = $amount;
|
||||
$log->log = $logMessage;
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PaginationHelper
|
||||
{
|
||||
public static function paginate(Collection $results, $pageSize)
|
||||
{
|
||||
$page = Paginator::resolveCurrentPage('page');
|
||||
|
||||
$total = $results->count();
|
||||
|
||||
return self::paginator($results->forPage($page, $pageSize), $total, $pageSize, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
'pageName' => 'page',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new length-aware paginator instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $items
|
||||
* @param int $total
|
||||
* @param int $perPage
|
||||
* @param int $currentPage
|
||||
* @param array $options
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected static function paginator($items, $total, $perPage, $currentPage, $options)
|
||||
{
|
||||
return Container::getInstance()->makeWith(LengthAwarePaginator::class, compact(
|
||||
'items', 'total', 'perPage', 'currentPage', 'options'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\LoanerType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* checks login credentials
|
||||
* @param Request $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function authenticate(Request $request)
|
||||
{
|
||||
//validates username and password
|
||||
$credentials = $request->validate([
|
||||
'username' => ['required','string'],
|
||||
'password' => ['required'],
|
||||
|
||||
]);
|
||||
|
||||
//gets the user
|
||||
$user = User::firstWhere('username', "=", $request['username']);
|
||||
//if user is an AD User or not in the database Check login with AD LDAP
|
||||
switch(config('app.login_mode')){
|
||||
case('db'):
|
||||
if (Auth::guard('nadUser')->attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return $this->getRedirect($user);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (empty($user)) {
|
||||
//check if user exist on the AD and if it does import the data form the ad and make it an AD User
|
||||
if ($adUser = \LdapRecord\Models\ActiveDirectory\User::findBy('samaccountname', $request['username'])) {
|
||||
echo $adUser;
|
||||
$ad_parts = explode(',',$adUser);
|
||||
$name_parts = explode('=',$ad_parts[0]);
|
||||
$name = $name_parts[1];
|
||||
|
||||
$ad_user = new User();
|
||||
$ad_user->guid = $adUser->getConvertedGuid();
|
||||
$ad_user->domain = 'default';
|
||||
$ad_user->name = $name;
|
||||
$ad_user->username = $request['username'];
|
||||
$ad_user->password = Hash::make($request['password']);
|
||||
$ad_user->loanerType()->associate(LoanerType::firstWhere('name', "=", 'adUser')->id);
|
||||
$ad_user->role()->associate(Role::firstWhere('name', "=", 'Elev')->id);
|
||||
$ad_user->save();
|
||||
|
||||
//login with AD
|
||||
if (Auth::guard('adUser')->attempt(['samaccountname' => $credentials['username'], 'password' => $credentials['password']])) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($user->loanerType->name === 'adUser'){
|
||||
if (Auth::guard('adUser')->attempt(['samaccountname' => $credentials['username'], 'password' => $credentials['password']])) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
elseif ($user->loanerType->name === 'nadUser') {
|
||||
if (Auth::guard('nadUser')->attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
return redirect()->route('users.show',['user' => $user]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//if the login fails
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
return back()->withInput($request->input())->withErrors([
|
||||
'username' => 'The provided credentials do not match our records.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the login page
|
||||
* @return Application|Factory|View|RedirectResponse
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
if(Auth::check()){
|
||||
return $this->getRedirect(Auth::user());
|
||||
}
|
||||
|
||||
return view('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* logs a user out of the system
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
Session::flush();
|
||||
return redirect()->intended('login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cabel;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = CabelCategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = CabelCategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = CabelCategory::Paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabelCategories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','cabelCategory')
|
||||
->with('data_names','cabelCategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = CabelCategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = CabelCategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = CabelCategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabelCategories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('cabelCategories.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$category = new CabelCategory();
|
||||
$category->name = $request->name;
|
||||
$category->save();
|
||||
|
||||
Logger::LogCreated($category->id,get_class($category));
|
||||
|
||||
return redirect()->route('cabelCategories.show',['cabelCategory' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
|
||||
return view('cabelCategories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
|
||||
return view('cabelCategories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabelCategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('cabelCategories.show',['cabelCategory' => $object]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
|
||||
|
||||
return redirect()->route('cabelCategories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('cabelCategories.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\CabelCategory $cabelcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($cabelcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabelCategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = CabelCategory::where('id','=',$cabelcategory)->withTrashed()->first();
|
||||
$object->restore();
|
||||
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('cabelCategories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Cabel;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cabel;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_cabels = Cabel::all();
|
||||
$cabel_collection = collect();
|
||||
foreach($all_cabels as $cabel){
|
||||
$loans = count($cabel->loans);
|
||||
$reservations = count($cabel->reservations);
|
||||
$total = $cabel->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$cabels = PaginationHelper::paginate($cabel_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$cabels = Cabel::paginate($PerPagination);
|
||||
}
|
||||
return view('cabels.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$cabels)
|
||||
->with('data_name','cabel')
|
||||
->with('data_names','cabels')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$cabels = Cabel::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_cabels = Cabel::all();
|
||||
$cabel_collection = collect();
|
||||
foreach($all_cabels as $cabel){
|
||||
$loans = count($cabel->loans);
|
||||
$reservations = count($cabel->reservations);
|
||||
$total = $cabel->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$cabel_collection->add($cabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$cabels = PaginationHelper::paginate($cabel_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$cabels = Cabel::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$cabels = Cabel::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$cabels = Cabel::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$cabels = Cabel::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('cabels.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$cabels)
|
||||
->with('data_name','cabel')
|
||||
->with('data_names','cabels')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('cabels.create')
|
||||
->with('categories',CabelCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$cabel = new Cabel();
|
||||
$cabel->cabel_category_id = $request->category_id;
|
||||
$cabel->name = $request->name;
|
||||
$cabel->save();
|
||||
|
||||
Logger::LogCreated($cabel->id,get_class($cabel));
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Cabel $cabel
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
|
||||
return view('cabels.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','cabel')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
|
||||
return view('cabels.edit')
|
||||
->with('categories',CabelCategory::all())
|
||||
->with('data',$object)
|
||||
->with('data_name','cabel')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
if($object->cabel_category_id != $request->category_id){
|
||||
$CabelCategory = CabelCategory::where('id','=',$request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),$logMessage = "Kategori : ".$object->category->name." til ".$CabelCategory->name);
|
||||
$object->cabel_category_id = $request->category_id;
|
||||
|
||||
}
|
||||
if($object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),$logMessage = "Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('cabels.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::withTrashed()->where('id','=',$cabel)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('cabels.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($cabel)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::withTrashed()->where('id','=',$cabel)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('cabels.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified amount to the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_add($cabel,Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_amount_add'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->first();
|
||||
$object->total += $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
|
||||
/**Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
* Remove the specified amount from the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_remove($cabel,Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'cabels_amount_remove'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Cabel::where('id','=',$cabel)->first();
|
||||
$object->total -= $request->amount;
|
||||
$object->save();
|
||||
|
||||
Logger::LogAmountRemoved($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('cabels.show',['cabel' => $cabel]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Loan;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Note;
|
||||
use App\Models\NoteType;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class NoteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "user"));
|
||||
array_push($search_types,array("value" => "type", "name" => "type"));
|
||||
array_push($search_types,array("value" => "note", "name" => "note"));
|
||||
array_push($search_types,array("value" => "created", "name" => "created_at"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "note":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where('note','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where('note','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "type":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('type',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$notes = Note::where(function ($query) use ($search_term){
|
||||
$query->whereHas('type',function ($query) use ($search_term){
|
||||
$query->where('name','like','%'.$search_term.'%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "created":
|
||||
switch($search_compare){
|
||||
default:
|
||||
$parts = explode('.',$search_term);
|
||||
$d = $parts[0];
|
||||
$m = $parts[1];
|
||||
$y = $parts[2];
|
||||
$constructed_date = $y."-".$m."-".$d;
|
||||
$notes = Note::where('created_at','like','%'.$constructed_date.'%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$notes = Note::Paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('notes.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$notes)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('without_create','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$notes = Note::onlyTrashed()->Paginate($PerPagination);
|
||||
|
||||
return view('notes.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$notes)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('without_create','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($note)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
$note_types = NoteType::all();
|
||||
|
||||
return view('notes.edit')
|
||||
->with('data',$note_obj)
|
||||
->with('data_name','note')
|
||||
->with('data_names','notes')
|
||||
->with('types',$note_types)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
|
||||
if($note_obj->note_type_id != $request->type){
|
||||
$type = NoteType::where('id','=',$request->type)->first();
|
||||
Logger::LogEdited($note_obj->id,get_class($note_obj),"Type : ".$note_obj->type->name." til ".$type->name);
|
||||
$note_obj->note_type_id = $request->type;
|
||||
}
|
||||
if($note_obj->note != $request->note) {
|
||||
Logger::LogEdited($note_obj->id,get_class($note_obj),"Note : ".$note_obj->note." til ".$request->note);
|
||||
$note_obj->note = $request->note;
|
||||
}
|
||||
$note_obj->save();
|
||||
|
||||
return redirect()->route('notes.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::where('id','=',$note)->first();
|
||||
Logger::LogDeleted($note_obj->id,get_class($note_obj));
|
||||
$note_obj->delete();
|
||||
|
||||
return redirect()->route('notes.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
Logger::LogForceDeleted($note_obj->id,get_class($note_obj));
|
||||
$note_obj->forceDelete();
|
||||
|
||||
return redirect()->route('notes.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($note)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'notes_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$note_obj = Note::withTrashed()->where('id','=',$note)->first();
|
||||
$note_obj->restore();
|
||||
Logger::LogRestored($note_obj->id,get_class($note_obj));
|
||||
|
||||
return redirect()->route('notes.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Loan;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Illuminate\Auth\Access\Response as Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response as Fresponse;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class PdfController extends Controller
|
||||
{
|
||||
public function index(Request $request){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "user", "name" => "user"));
|
||||
array_push($search_types,array("value" => "date", "name" => "date"));
|
||||
array_push($search_types,array("value" => "type", "name" => "type"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "user":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$contracts = Contract::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
});
|
||||
})
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$contracts = Contract::where(function ($query) use ($search_term){
|
||||
$query->whereHas('user',function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
});
|
||||
})
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "type":
|
||||
switch($search_compare){
|
||||
default:
|
||||
$contracts = Contract::where('type','=',trans($search_term))
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "date":
|
||||
switch($search_compare){
|
||||
case('>='):
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','>=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
case('<='):
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','<=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$parts = explode(' ',$search_term);
|
||||
$date_part = $parts[0];
|
||||
$time_part = $parts[1];
|
||||
$date_parts = explode('.',$date_part);
|
||||
$d = $date_parts[0];
|
||||
$m = $date_parts[1];
|
||||
$y = $date_parts[2];
|
||||
$time_parts = explode(':',$time_part);
|
||||
$h = $time_parts[0];
|
||||
$i = $time_parts[1];
|
||||
$s = $time_parts[2];
|
||||
$date = new DateTime();
|
||||
$timezone = new DateTimeZone('Europe/Copenhagen');
|
||||
$date->setTimezone($timezone);
|
||||
$date->setDate($y,$m,$d);
|
||||
$date->setTime($h,$i,$s);
|
||||
$timestamp = $date->getTimestamp();
|
||||
$contracts = Contract::where('timestamp','=',$timestamp)
|
||||
->orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$contracts = Contract::orderBy('user_id')
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('contracts.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data_name','contract')
|
||||
->with('data_names','contracts')
|
||||
->with('data',$contracts)
|
||||
;
|
||||
}
|
||||
|
||||
public function show(Request $request,$user){
|
||||
$user_obj = User::where('username','=',$user)->first();
|
||||
|
||||
if(empty($user_obj)){
|
||||
$user_obj = User::where('name','=',$request->user)->first();
|
||||
}
|
||||
|
||||
if(Auth::user()->id != $user_obj->id){
|
||||
if(!Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_view'))){
|
||||
return redirect()->intended(route('users.show',Auth::user()));
|
||||
}
|
||||
else{
|
||||
$user = $request->user;
|
||||
$type = $request->type;
|
||||
|
||||
$timestamp = $request->timestamp;
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
return Fresponse::file($file_full);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$user = $request->user;
|
||||
$type = $request->type;
|
||||
|
||||
$timestamp = $request->timestamp;
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
return Fresponse::file($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy(Request $request){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'pdf_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$type = $request->type;
|
||||
$user = $request->user;
|
||||
$timestamp = $request->timestamp;
|
||||
|
||||
$file_name = utf8_encode('app/'.$type."/".$user."_".$timestamp.".pdf");
|
||||
$file_full = storage_path($file_name);
|
||||
|
||||
if(file_exists($file_full)){
|
||||
unlink($file_full);
|
||||
}
|
||||
|
||||
$user_obj = User::where('username','=',$user)->first();
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Cabel;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Log;
|
||||
use App\Models\LogAction;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OtherController extends Controller
|
||||
{
|
||||
public function logs(Request $request){
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$logs = Log::orderBy('created_at','desc')->Paginate($PerPagination);
|
||||
|
||||
return view('logs')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$logs)
|
||||
->with('data_name','log')
|
||||
->with('data_names','logs')
|
||||
->with('no_deleted',true)
|
||||
;
|
||||
}
|
||||
|
||||
public function statistics(Request $request){
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$products = Product::all();
|
||||
$cabels = Cabel::all();
|
||||
$loans = Loan::where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id')
|
||||
->get()
|
||||
;
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$log_returned = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)->get();
|
||||
$log_returned_placement = Log::where('log_action_id','=',LogAction::where('name','=','returned')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id','created_at')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_lent = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)->get();
|
||||
$log_lent_placement = Log::where('log_action_id','=',LogAction::where('name','=','lent')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_reserved = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)->get();
|
||||
$log_reserved_placement = Log::where('log_action_id','=',LogAction::where('name','=','reserved')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('sum','desc')
|
||||
->get()
|
||||
;
|
||||
$log_validated = Log::where('log_action_id','=',LogAction::where('name','=','validated')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_setups = Log::where('log_action_id','=',LogAction::where('name','=','set up')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_pickups = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)->get();
|
||||
$log_pickups_placement = Log::where('log_action_id','=',LogAction::where('name','=','picked up')->first()->id)
|
||||
->select('*',DB::raw('SUM(amount) as sum'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$log_notes = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)->get();
|
||||
$log_notes_placement = Log::where('log_action_id','=',LogAction::where('name','=','note')->first()->id)
|
||||
->select('*',DB::raw('count(user_id) as amount'))
|
||||
->groupBy('user_id')
|
||||
->orderBy('amount','desc')
|
||||
->get()
|
||||
;
|
||||
$total_lent = 0;
|
||||
$total_reserved = 0;
|
||||
$total_total = 0;
|
||||
|
||||
$lastday_date = Carbon::now()->subDays(1)->toDateTimeString();
|
||||
$lastday_lent = 0;
|
||||
$lastday_reserved = 0;
|
||||
$lastday_returned = 0;
|
||||
$lastday_notes = 0;
|
||||
|
||||
foreach($products as $product){
|
||||
$total_total += $product->total;
|
||||
}
|
||||
|
||||
foreach($cabels as $cabel){
|
||||
$total_total += $cabel->total;
|
||||
}
|
||||
|
||||
foreach($loans as $loan){
|
||||
$total_lent += $loan->amount;
|
||||
}
|
||||
|
||||
foreach($reservations as $reservation){
|
||||
$total_reserved += $reservation->amount;
|
||||
}
|
||||
|
||||
foreach($log_lent as $loan){
|
||||
if($loan->created_at >= $lastday_date){
|
||||
$lastday_lent += $loan->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_reserved as $loan){
|
||||
if($loan->created_at >= $lastday_date){
|
||||
$lastday_reserved += $loan->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_returned as $return){
|
||||
if($return->created_at >= $lastday_date){
|
||||
$lastday_returned += $return->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_pickups as $pickup){
|
||||
if($pickup->created_at >= $lastday_date){
|
||||
$lastday_returned += $pickup->amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($log_notes as $note){
|
||||
if($note->created_at >= $lastday_date){
|
||||
$lastday_notes += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return view('statistics')
|
||||
->with('search_types',$search_types)
|
||||
->with('data_name','statistic')
|
||||
->with('data_names','statistics')
|
||||
->with('lastday_lent',$lastday_lent)
|
||||
->with('lastday_reserved',$lastday_reserved)
|
||||
->with('lastday_returned',$lastday_returned)
|
||||
->with('lastday_notes',$lastday_notes)
|
||||
->with('total_lent',$total_lent)
|
||||
->with('total_reserved',$total_reserved)
|
||||
->with('total_total',$total_total)
|
||||
->with('validated',$log_validated)
|
||||
->with('lent',$log_lent_placement)
|
||||
->with('reserved',$log_reserved_placement)
|
||||
->with('setups',$log_setups)
|
||||
->with('pickups',$log_pickups_placement)
|
||||
->with('returned',$log_returned_placement)
|
||||
->with('notes',$log_notes_placement)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$brands = Brand::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$brands = Brand::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$brands = Brand::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('brands.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$brands)
|
||||
->with('data_name','brand')
|
||||
->with('data_names','brands')
|
||||
;
|
||||
}
|
||||
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$brands = Brand::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$brands = Brand::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$brands = Brand::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('brands.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$brands)
|
||||
->with('data_name','brand')
|
||||
->with('data_names','brands')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('brands.create')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$brand = new Brand();
|
||||
$brand->name = $request->name;
|
||||
$brand->save();
|
||||
Logger::LogCreated($brand->id,get_class($brand));
|
||||
|
||||
return redirect()->route('brands.show',['brand' => $brand]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
return view('brands.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','brand')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
|
||||
return view('brands.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','brand')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('brands.show',['brand' => $brand]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('brands.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('brands.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently emove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Brand $brand
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($brand)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'brands_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Brand::withTrashed()->where('id','=',$brand)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('brands.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductCategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductCategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductCategory::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('categories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','category')
|
||||
->with('data_names','categories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? '10';
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductCategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductCategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductCategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('categories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','category')
|
||||
->with('data_names','categories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('categories.create')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$category = new ProductCategory();
|
||||
$category->name = $request->name;
|
||||
$category->save();
|
||||
Logger::LogCreated($category->id,get_class($category));
|
||||
|
||||
return redirect()->route('categories.show',['category' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
|
||||
return view('categories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','category')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
|
||||
return view('categories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','category')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProductCategory $category
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('categories.show',['category' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('categories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('categories.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($category)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'categories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductCategory::withTrashed()->where('id','=',$category)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('categories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Helpers\PaginationHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\ProductSubcategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
if(config('app.barcode_mode') == 'static'){
|
||||
array_push($search_types,array("value" => "barcode", "name" => "barcode"));
|
||||
}
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
array_push($search_types,array("value" => "subcategory", "name" => "subcategory"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
array_push($search_types,array("value" => "model", "name" => "model"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "description", "name" => "description"));
|
||||
|
||||
array_push($search_types,array("value" => "available", "name" => "available"));
|
||||
array_push($search_types,array("value" => "loans", "name" => "loaned"));
|
||||
array_push($search_types,array("value" => "reservations", "name" => "reserved"));
|
||||
array_push($search_types,array("value" => "total", "name" => "total"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "subcategory":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('subcategory',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('subcategory',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "model":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('model',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where(function ($query) use ($search_term){
|
||||
$query->whereHas('model',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "description":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$products = Product::where('description','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('description','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "available":
|
||||
$all_products = Product::all();
|
||||
$product_collection = collect();
|
||||
foreach($all_products as $product){
|
||||
$loans = count($product->loans);
|
||||
$reservations = count($product->reservations);
|
||||
$total = $product->total;
|
||||
$available = $total - ($loans + $reservations);
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
if($available >= $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
case("<="):
|
||||
if($available <= $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
case("="):
|
||||
if($available == $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($available == $search_term){
|
||||
$product_collection->add($product);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
$products = PaginationHelper::paginate($product_collection, $PerPagination);
|
||||
break;
|
||||
case "loans":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::has('loans', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::has('loans', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::has('loans', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "reservations":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::has('reservations', '>=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::has('reservations', '<=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::has('reservations', '=' , $search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "total":
|
||||
switch($search_compare){
|
||||
case(">="):
|
||||
$products = Product::where('total','>=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("<="):
|
||||
$products = Product::where('total','<=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
case("="):
|
||||
$products = Product::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$products = Product::where('total','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$products = Product::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('products.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$products)
|
||||
->with('data_name','product')
|
||||
->with('data_names','products')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
if(config('app.barcode_mode') == 'static'){
|
||||
array_push($search_types,array("value" => "barcode", "name" => "barcode"));
|
||||
}
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
array_push($search_types,array("value" => "subcategory", "name" => "subcategory"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
array_push($search_types,array("value" => "model", "name" => "model"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "description", "name" => "description"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
$products = Product::onlyTrashed()->Paginate($PerPagination);
|
||||
|
||||
return view('products.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$products)
|
||||
->with('data_name','product')
|
||||
->with('data_names','products')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('products.create')
|
||||
->with('categories',ProductCategory::all())
|
||||
->with('subcategories',ProductSubcategory::all())
|
||||
->with('brands',Brand::has('models')->get())
|
||||
->with('models',ProductModel::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$product = new Product();
|
||||
if(isset($request->barcode)){
|
||||
$product->barcode = $request->barcode;
|
||||
}
|
||||
$product->product_category_id = $request->category_id;
|
||||
$product->product_subcategory_id = $request->subcategory_id;
|
||||
$product->brand_id = $request->brand_id;
|
||||
$product->product_model_id = $request->model_id;
|
||||
$product->name = $request->name;
|
||||
$product->description = $request->description;
|
||||
$product->save();
|
||||
|
||||
Logger::LogCreated($product->id,get_class($product));
|
||||
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
return view('products.show')
|
||||
->with('data',$object)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
|
||||
return view('products.edit')
|
||||
->with('categories',ProductCategory::withTrashed()->get())
|
||||
->with('subcategories',ProductSubcategory::withTrashed()->get())
|
||||
->with('brands',Brand::withTrashed()->has('models')->get())
|
||||
->with('models',ProductModel::withTrashed()->get())
|
||||
->with('data',$object)
|
||||
->with('data_name','product')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
|
||||
if(isset($request->barcode)){
|
||||
if($object->barcode != $request->barcode){
|
||||
Logger::LogEdited($object->id,get_class($object),"Stregkode : ".$object->barcode." til ".$request->barcode);
|
||||
$object->barcode = $request->barcode;
|
||||
}
|
||||
}
|
||||
if($object->product_category_id != $request->category_id) {
|
||||
$category = ProductCategory::where('id','=', $request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Kategori : ".$object->category->name." til ".$category->name);
|
||||
$object->product_category_id = $request->category_id;
|
||||
}
|
||||
if($object->product_subcategory_id != $request->subcategory_id) {
|
||||
$subcategory = ProductSubcategory::where('id','=', $request->subcategory_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Underkategori : ".$object->subcategory->name." til ".$subcategory->name);
|
||||
$object->product_subcategory_id = $request->subcategory_id;
|
||||
}
|
||||
if($object->brand_id != $request->brand_id) {
|
||||
$brand = Brand::where('id','=', $request->brand_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Fabrikant : ".$object->brand_id->name." til ".$brand->name);
|
||||
$object->brand_id = $request->brand_id;
|
||||
}
|
||||
if($object->product_model_id != $request->model_id) {
|
||||
$model = ProductModel::where('id','=', $request->model_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Model : ".$object->model->name." til ".$model->name);
|
||||
$object->product_model_id = $request->model_id;
|
||||
}
|
||||
if($object->name != $request->name) {
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if($object->description != $request->description) {
|
||||
Logger::LogEdited($object->id,get_class($object),"Beskrivels : ".$object->description." til ".$request->description);
|
||||
$object->description = $request->description;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
return redirect()->route('products.index');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
$object->restore();
|
||||
|
||||
return redirect()->route('products.deleted');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function forceDelete($product)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'products_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('products.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified amount to the Pool.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_add($product,Request $request)
|
||||
{
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
$object->total += $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountAdded($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('products.show',['product' => $product]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified amount from the Pool.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function amount_remove(Product $product,Request $request)
|
||||
{
|
||||
$object = Product::withTrashed()->where('id','=',$product)->first();
|
||||
$object->total -= $request->amount;
|
||||
$object->save();
|
||||
Logger::LogAmountRemoved($object->id,get_class($object),$request->amount);
|
||||
|
||||
return redirect()->route('products.show',['product' => $product]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductModel;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductModelController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$models = ProductModel::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('models.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$models)
|
||||
->with('data_name','model')
|
||||
->with('data_names','models')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "brand", "name" => "brand"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "brand":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$models = ProductModel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$models = ProductModel::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('brand',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$models = ProductModel::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('models.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$models)
|
||||
->with('data_name','model')
|
||||
->with('data_names','models')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('models.create')
|
||||
->with('brands',Brand::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$model = new ProductModel();
|
||||
$model->name = $request->name;
|
||||
$model->brand_id = $request->brand_id;
|
||||
$model->save();
|
||||
Logger::LogCreated($model->id,get_class($model));
|
||||
|
||||
return redirect()->route('models.show',['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
return view('models.show')
|
||||
->with('data',$object)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
return view('models.edit')
|
||||
->with('data',$object)
|
||||
->with('brands',Brand::withTrashed()->get())
|
||||
->with('data_name','model')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->brand_id != $request->brand_id){
|
||||
$brand = Brand::withTrashed()->where('id','=',$request->brand_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Fabrikant : ".$object->brand->name." til ".$brand->name);
|
||||
$object->brand_id = $request->brand_id;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('models.show',['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('models.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('models.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($model)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'models_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductModel::withTrashed()->where('id','=',$model)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('models.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Product;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Permission;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductSubcategory;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductSubcategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "category", "name" => "category"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductSubcategory::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('subcategories.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','subcategory')
|
||||
->with('data_names','subcategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::onlyTrashed()->where('name','=',$search_term)->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::onlyTrashed()->where('name','like','%' . $search_term . '%')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "category":
|
||||
switch($search_compare){
|
||||
case("="):
|
||||
$categories = ProductSubcategory::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$categories = ProductSubcategory::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('category',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$categories = ProductSubcategory::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('subcategories.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$categories)
|
||||
->with('data_name','subcategory')
|
||||
->with('data_names','subcategories')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('subcategories.create')
|
||||
->with('categories',ProductCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$subcategory = new ProductSubcategory();
|
||||
$subcategory->name = $request->name;
|
||||
$subcategory->product_category_id = $request->category_id;
|
||||
$subcategory->save();
|
||||
Logger::LogCreated($subcategory->id,get_class($subcategory));
|
||||
|
||||
return redirect()->route('subcategories.show',['subcategory' => $subcategory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
return view('subcategories.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','subcategory')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
|
||||
$data_type = "subcategory";
|
||||
|
||||
return view('subcategories.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name',$data_type)
|
||||
->with('categories',ProductCategory::all())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\ProductSubcategory $subcategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request,$subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->product_category_id != $request->category_id){
|
||||
$category = ProductCategory::withTrashed()->where('id','=',$request->category_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Kategori : ".$object->category->name." til ".$category->name);
|
||||
$object->product_category_id = $request->category_id;
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('subcategories.show',['subcategory' => $subcategory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('subcategories.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete_force($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
|
||||
return redirect()->route('subcategories.deleted');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function restore($subcategory)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'subcategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = ProductSubcategory::withTrashed()->where('id','=',$subcategory)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('subcategories.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BuildingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p');
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::onlyTrashed()->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('buildings.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$building = new Building();
|
||||
$building->name = $request->name;
|
||||
$building->save();
|
||||
Logger::LogCreated($building->id,get_class($building));
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function show($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
|
||||
return view('buildings.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function edit($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
return view('buildings.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('buildings.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoomController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
case "name":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
->with('data_names','rooms')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? '10';
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
break;
|
||||
case "room":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::onlyTrashed()->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->onlyTrashed()->Paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('rooms.create')
|
||||
->with('buildings',Building::all()->sortBy(['name','asc']))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$room = new Room();
|
||||
$room->building_id = $request->building_id;
|
||||
$room->name = $request->name;
|
||||
$room->save();
|
||||
Logger::LogCreated($room->id,get_class($room));
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Room $room
|
||||
*/
|
||||
public function show($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('room_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','loan_type_id','room_id')
|
||||
->orderBy('loan_type_id')
|
||||
->orderBy('user_id')
|
||||
->orderBy('date_start')
|
||||
->orderBy('date_end')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
return view('rooms.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','room')
|
||||
->with('reservations',$reservations)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
return view('rooms.edit')
|
||||
->with('data',$object)
|
||||
->with('buildings',Building::all()->sortBy([['name','asc']]))
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$object->building_id = $request->building_id;
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->building_id != $request->building_id){
|
||||
$building = Building::withTrashed()->where('id','=',$request->building_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->building->name." til ".$building->name);
|
||||
$object->building_id = $request->building_id;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('rooms.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Helpers\ActionLogger;
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cabelcategory;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanerType;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Note;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "username"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name_full"));
|
||||
array_push($search_types,array("value" => "role", "name" => "role"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "role":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$users = User::paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('users.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$users)
|
||||
->with('data_name','user')
|
||||
->with('data_names','users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "username", "name" => "username"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
array_push($search_types,array("value" => "role", "name" => "role"));
|
||||
|
||||
$PerPagination = $request->input('p');
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "username":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case "name":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "role":
|
||||
switch($search_compare){
|
||||
case('='):
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','=',$search_term);
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->whereHas('role',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$users = User::onlyTrashed()->where(function ($query) use ($search_term){
|
||||
$query->where('username', 'like', '%'.$search_term.'%')
|
||||
->orWhere('name', 'like', '%'.$search_term.'%')
|
||||
->orWhereHas('role', function ($query) use ($search_term){
|
||||
$query->where('name', 'like', '%'.$search_term.'%');
|
||||
});
|
||||
})->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$users = User::onlyTrashed()->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('users.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$users)
|
||||
->with('data_name','user')
|
||||
->with('data_names','users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_ceate'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$exclude = array();
|
||||
if(Auth::user()->role->name != "Administrator"){
|
||||
array_push($exclude,Role::firstWhere("name", "=", "Administrator")->id);
|
||||
}
|
||||
|
||||
return view('users.create')
|
||||
->with('loanerTypes', LoanerType::all())
|
||||
->with('roles', Role::all()->except($exclude))
|
||||
->with('password_input_repeat','true')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$nadUser = LoanerType::where('name','=','nadUser')->first();
|
||||
$user = new User();
|
||||
$user->name = $request->name;
|
||||
$user->username = $request->username;
|
||||
$user->password = Hash::make($request->password);
|
||||
$user->loaner_type_id = $nadUser->id;
|
||||
$user->role_id = $request->role_id;
|
||||
$user->save();
|
||||
Logger::LogCreated($user->id,get_class($user));
|
||||
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show($user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
$loans = Loan::where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('user_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','date_start','date_end')
|
||||
->orderBy('date_end')
|
||||
->orderBy('date_start')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('user_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','loan_type_id','room_id')
|
||||
->orderBy('loan_type_id')
|
||||
->orderBy('room_id')
|
||||
->orderBy('date_start')
|
||||
->orderBy('date_end')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
$notes = Note::where('user_id','=',$object->id)
|
||||
->get()
|
||||
;
|
||||
|
||||
$contracts = Contract::where('user_id','=',$object->id)
|
||||
->orderBy('type')
|
||||
->orderBy('timestamp','desc')
|
||||
->get()
|
||||
;
|
||||
|
||||
return view('users.show')
|
||||
->with('data',$object)
|
||||
->with('loans',$loans)
|
||||
->with('reservations',$reservations)
|
||||
->with('contracts',$contracts)
|
||||
->with('notes',$notes)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
$exclude = array();
|
||||
if(Auth::user()->role->name != "Administrator"){
|
||||
array_push($exclude,Role::where("name","=","Administrator")->first()->id);
|
||||
}
|
||||
|
||||
return view('users.edit')
|
||||
->with('data', $object)
|
||||
->with('loanerTypes', LoanerType::all())
|
||||
->with('users', User::all())
|
||||
->with('roles', Role::all()->except($exclude))
|
||||
->with('password_input_repeat','true')
|
||||
->with('data_name', 'user')
|
||||
->with('data_names', 'users')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $user)
|
||||
{
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
if(Auth::user()->id != $object->id){
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
return redirect()->route('roles.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
|
||||
$laptop_files = Storage::files('laptops');
|
||||
foreach($laptop_files as $file){
|
||||
$no_dir = str_replace("laptops/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
$reservation_files = Storage::files('reservation');
|
||||
foreach($reservation_files as $file){
|
||||
$no_dir = str_replace("reservation/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
$contract_files = Storage::files('contracts');
|
||||
foreach($contract_files as $file){
|
||||
$no_dir = str_replace("contracts/", "",$file);
|
||||
$parts = explode('_',$no_dir);
|
||||
$file_name = 'app\\'.$file;
|
||||
$file_full = storage_path($file_name);
|
||||
if($parts[0] == $object->username){
|
||||
unlink($file_full);
|
||||
}
|
||||
}
|
||||
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($user)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'user_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = User::withTrashed()->where('id','=',$user)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('users.index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param string|null ...$guards
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $ignore = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Brand extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function models()
|
||||
{
|
||||
return $this->hasMany(ProductModel::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Building extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function rooms()
|
||||
{
|
||||
return $this->hasMany(Room::class,'building_id','id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Cabel extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CabelCategory::class,'cabel_category_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)->withTrashed();
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)->withTrashed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CabelCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function cabels()
|
||||
{
|
||||
return $this->hasMany(Cabel::class,'cabel_category_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'timestamp',
|
||||
'user_id',
|
||||
'type'
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Loan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'room_id',
|
||||
'loan_type_id',
|
||||
'loanable_id',
|
||||
'loanable_type',
|
||||
'date_start',
|
||||
'date_end',
|
||||
'date_deadline',
|
||||
];
|
||||
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function room()
|
||||
{
|
||||
return $this->belongsTo(Room::class, 'room_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
return $this->belongsTo(LoanType::class, 'loan_type_id');
|
||||
}
|
||||
|
||||
public function loanable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LoanType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = "loan_types";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LoanerType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'target_id',
|
||||
'loggable_type',
|
||||
'loggable_id',
|
||||
'log',
|
||||
'amount'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function target()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'target_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function action()
|
||||
{
|
||||
return $this->belongsTo(LogAction::class, 'log_action_id');
|
||||
}
|
||||
|
||||
public function loggable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LogAction extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Note extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'note_type_id',
|
||||
'user_id',
|
||||
'note',
|
||||
'loanable_type',
|
||||
'loanable_id'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class,'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
return $this->belongsTo(NoteType::class,'note_type_id');
|
||||
}
|
||||
|
||||
public function loanable()
|
||||
{
|
||||
return $this->morphTo()->withTrashed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NoteType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets all the Roles with a relation with the Permission(Many to Many through role_has_permission)
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, "role_has_permission", "permission_id", "role_id")->withTimestamps();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function subcategory()
|
||||
{
|
||||
return $this->belongsTo(ProductSubcategory::class,'product_subcategory_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function brand()
|
||||
{
|
||||
return $this->belongsTo(Brand::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function model()
|
||||
{
|
||||
return $this->belongsTo(ProductModel::class,'product_model_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id);
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function subcategories()
|
||||
{
|
||||
return $this->hasMany(ProductSubcategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductModel extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'brand_id'
|
||||
];
|
||||
|
||||
public function brand()
|
||||
{
|
||||
return $this->belongsTo(Brand::class,'brand_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_model_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductSubcategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'product_category_id'
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ProductCategory::class,'product_category_id','id')->withTrashed();
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class,'product_subcategory_id','id')->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets all the Permissions with a relation with the roles(Many to Many through role_has_permission)
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function permissions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, "role_has_permission", 'role_id', 'permission_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class,'role_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Room extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
public function building()
|
||||
{
|
||||
return $this->belongsTo(Building::class,'building_id','id')->withTrashed()
|
||||
;
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'room_id')
|
||||
->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\users\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
|
||||
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
|
||||
|
||||
class User extends Authenticatable implements LdapAuthenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, AuthenticatesWithLdap;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'password',
|
||||
'guid',
|
||||
'domain'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Gets the Loaner Type that the users belongs to
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function loanerType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanerType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the roles that the users belongs to
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Role::class);
|
||||
}
|
||||
|
||||
public function loans()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'user_id')
|
||||
->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany(Loan::class,'user_id')
|
||||
->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
;
|
||||
}
|
||||
|
||||
public function notes()
|
||||
{
|
||||
return $this->hasMany(Note::class,'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Brand;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BrandPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param Brand $Brand
|
||||
* @param User $model
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param Brand $Brand
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param Brand $Brand
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param Brand $Brand
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param Brand $Brand
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','brands_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Building;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BuildingPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','buildings_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\CabelCategory;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelCategoryPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabelCategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Cabel;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CabelPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete_force(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can add to the pool.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function amount_add()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_amount_add'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can remove from the pool.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function amount_remove()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','cabels_amount_remove'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CategoryPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','categories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoanPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create_user(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_create_user'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create_laptop(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_create_laptop'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function adjust(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_adjust'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function return(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','loans_return'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Productmodel;
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ModelPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','models_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class NotePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any notes.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any notes.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create notes.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','notes_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class OtherPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','logs_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
public function home_page()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','home_page'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
public function statistics()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','statistics'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PDFPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','pdf_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','pdf_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','pdf_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can add to the pool.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function amount_add()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_amount_add'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can remove from the pool.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function amount_remove()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','products_amount_remove'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ReservationPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function extend(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_extend'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function return(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_return'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can validate the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function validate(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_validate'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can cancel the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function cancel(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_cancel'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function pickup(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_pickup'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function setup(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','reservations_setup'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RolePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function viewAny(): Response
|
||||
{
|
||||
//ConsoleLogger::DebugToConsole("users Policy - viewAny - returns: ".$user->role->permissions->contains(Permission::firstWhere('name', '=', 'user_view_any')));
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
//ConsoleLogger::DebugToConsole("users Policy - viewAny - returns: ".$user->role->permissions->contains(Permission::firstWhere('name', '=', 'user_view_any')));
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
//ConsoleLogger::DebugToConsole("users Policy - View - returns: ".$user->role->permissions->contains(Permission::firstWhere('name', '=', 'user_view')));
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function edit_permissions()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','roles_edit_permissions'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RoomPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','rooms_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SubcategoryPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function view(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force()
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name','=','subcategories_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function viewAny_deleted(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $model
|
||||
* @return Response
|
||||
*/
|
||||
public function view(User $user): Response
|
||||
{
|
||||
return ($user->id === Auth::user()->id
|
||||
or Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_view')))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create(): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(User $user): Response
|
||||
{
|
||||
return ($user->id === Auth::user()->id
|
||||
or Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit')))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response
|
||||
*/
|
||||
public function delete(User $user): Response
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function restore(User $user)
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function delete_force(User $user)
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function edit_username(User $user)
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit_username'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function edit_role(User $user)
|
||||
{
|
||||
return Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'users_edit_role'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Paginator::useBootstrap();
|
||||
Schema::defaultStringLength(191);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Building;
|
||||
use App\Models\Cabel;
|
||||
use App\Models\Cabelcategory;
|
||||
use App\Models\Note;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\ProductSubcategory;
|
||||
use App\Models\Role;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use App\Policies\BrandPolicy;
|
||||
use App\Policies\BuildingPolicy;
|
||||
use App\Policies\CabelcategoryPolicy;
|
||||
use App\Policies\CabelPolicy;
|
||||
use App\Policies\CategoryPolicy;
|
||||
use App\Policies\LoanPolicy;
|
||||
use App\Policies\ModelPolicy;
|
||||
use App\Policies\NotePolicy;
|
||||
use App\Policies\OtherPolicy;
|
||||
use App\Policies\PDFPolicy;
|
||||
use App\Policies\ProductPolicy;
|
||||
use App\Policies\ReservationPolicy;
|
||||
use App\Policies\RolePolicy;
|
||||
use App\Policies\RoomPolicy;
|
||||
use App\Policies\SubcategoryPolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\models' => 'App\Policies\ModelPolicy',
|
||||
Role::class => RolePolicy::class,
|
||||
User::class => UserPolicy::class,
|
||||
Building::class => BuildingPolicy::class,
|
||||
Room::class => RoomPolicy::class,
|
||||
Brand::class => BrandPolicy::class,
|
||||
ProductModel::class => ModelPolicy::class,
|
||||
ProductCategory::class => CategoryPolicy::class,
|
||||
ProductSubcategory::class => SubcategoryPolicy::class,
|
||||
Product::class => ProductPolicy::class,
|
||||
Cabel::class => CabelPolicy::class,
|
||||
Cabelcategory::class => CabelcategoryPolicy::class,
|
||||
Note::class => NotePolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
// users Policy
|
||||
Gate::define('users_viewAny', [UserPolicy::class,'viewAny']);
|
||||
Gate::define('users_viewAny_deleted', [UserPolicy::class,'viewAny_deleted']);
|
||||
Gate::define('users_view', [UserPolicy::class,'view']);
|
||||
Gate::define('users_edit', [UserPolicy::class,'edit']);
|
||||
Gate::define('users_edit_role', [UserPolicy::class,'edit_role']);
|
||||
Gate::define('users_edit_username', [UserPolicy::class,'edit_username']);
|
||||
Gate::define('users_delete', [UserPolicy::class,'delete']);
|
||||
Gate::define('users_delete_force', [UserPolicy::class,'delete_force']);
|
||||
Gate::define('users_restore', [UserPolicy::class,'restore']);
|
||||
|
||||
// buildings Policy
|
||||
Gate::define('buildings_viewAny', [BuildingPolicy::class,'viewAny']);
|
||||
Gate::define('buildings_viewAny_deleted', [BuildingPolicy::class,'viewAny_deleted']);
|
||||
Gate::define('buildings_view', [BuildingPolicy::class,'view']);
|
||||
Gate::define('buildings_create', [BuildingPolicy::class,'create']);
|
||||
Gate::define('buildings_edit', [BuildingPolicy::class,'edit']);
|
||||
Gate::define('buildings_delete', [BuildingPolicy::class,'delete']);
|
||||
Gate::define('buildings_delete_force', [BuildingPolicy::class,'delete_force']);
|
||||
Gate::define('buildings_restore', [BuildingPolicy::class,'restore']);
|
||||
|
||||
// rooms Policy
|
||||
Gate::define('rooms_viewAny', [RoomPolicy::class,'viewAny']);
|
||||
Gate::define('rooms_viewAny_deleted', [RoomPolicy::class,'viewAny_deleted']);
|
||||
Gate::define('rooms_view', [RoomPolicy::class,'view']);
|
||||
Gate::define('rooms_create', [RoomPolicy::class,'create']);
|
||||
Gate::define('rooms_edit', [RoomPolicy::class,'edit']);
|
||||
Gate::define('rooms_delete', [RoomPolicy::class,'delete']);
|
||||
Gate::define('rooms_delete_force', [RoomPolicy::class,'delete_force']);
|
||||
Gate::define('rooms_restore', [RoomPolicy::class,'restore']);
|
||||
|
||||
//PDF
|
||||
Gate::define('pdf_viewAny',[PDFPolicy::class,'viewAny']);
|
||||
Gate::define('pdf_view',[PDFPolicy::class,'view']);
|
||||
Gate::define('pdf_delete',[PDFPolicy::class,'delete']);
|
||||
|
||||
// roles Policy
|
||||
Gate::define('roles_viewAny', [RolePolicy::class, 'viewAny']);
|
||||
Gate::define('roles_viewAny_deleted', [RolePolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('roles_view', [RolePolicy::class, 'view']);
|
||||
Gate::define('roles_create', [RolePolicy::class, 'create']);
|
||||
Gate::define('roles_edit', [RolePolicy::class, 'edit']);
|
||||
Gate::define('roles_edit_permissions', [RolePolicy::class, 'edit_permissions']);
|
||||
Gate::define('roles_delete', [RolePolicy::class, 'delete']);
|
||||
Gate::define('roles_delete_force', [RolePolicy::class, 'delete_force']);
|
||||
Gate::define('roles_restore', [RolePolicy::class, 'restore']);
|
||||
|
||||
// brands Policy
|
||||
Gate::define('brands_viewAny', [BrandPolicy::class, 'viewAny']);
|
||||
Gate::define('brands_viewAny_deleted', [BrandPolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('brands_view', [BrandPolicy::class, 'view']);
|
||||
Gate::define('brands_create', [BrandPolicy::class, 'create']);
|
||||
Gate::define('brands_edit', [BrandPolicy::class, 'edit']);
|
||||
Gate::define('brands_delete', [BrandPolicy::class, 'delete']);
|
||||
Gate::define('brands_delete_force', [BrandPolicy::class, 'delete_force']);
|
||||
Gate::define('brands_restore', [BrandPolicy::class, 'restore']);
|
||||
|
||||
// models Policy
|
||||
Gate::define('models_viewAny', [ModelPolicy::class, 'viewAny']);
|
||||
Gate::define('models_viewAny_deleted', [ModelPolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('models_view', [ModelPolicy::class, 'view']);
|
||||
Gate::define('models_create', [ModelPolicy::class, 'create']);
|
||||
Gate::define('models_edit', [ModelPolicy::class, 'edit']);
|
||||
Gate::define('models_delete', [ModelPolicy::class, 'delete']);
|
||||
Gate::define('models_delete_force', [ModelPolicy::class, 'delete_force']);
|
||||
Gate::define('models_restore', [ModelPolicy::class, 'restore']);
|
||||
|
||||
// categories Policy
|
||||
Gate::define('categories_viewAny', [CategoryPolicy::class, 'viewAny']);
|
||||
Gate::define('categories_viewAny_deleted', [CategoryPolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('categories_view', [CategoryPolicy::class, 'view']);
|
||||
Gate::define('categories_create', [CategoryPolicy::class, 'create']);
|
||||
Gate::define('categories_edit', [CategoryPolicy::class, 'edit']);
|
||||
Gate::define('categories_delete', [CategoryPolicy::class, 'delete']);
|
||||
Gate::define('categories_delete_force', [CategoryPolicy::class, 'delete_force']);
|
||||
Gate::define('categories_restore', [CategoryPolicy::class, 'restore']);
|
||||
|
||||
// subcategories Policy
|
||||
Gate::define('subcategories_viewAny', [SubcategoryPolicy::class, 'viewAny']);
|
||||
Gate::define('subcategories_viewAny_deleted', [SubcategoryPolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('subcategories_view', [SubcategoryPolicy::class, 'view']);
|
||||
Gate::define('subcategories_create', [SubcategoryPolicy::class, 'create']);
|
||||
Gate::define('subcategories_edit', [SubcategoryPolicy::class, 'edit']);
|
||||
Gate::define('subcategories_delete', [SubcategoryPolicy::class, 'delete']);
|
||||
Gate::define('subcategories_delete_force', [SubcategoryPolicy::class, 'delete_force']);
|
||||
Gate::define('subcategories_restore', [SubcategoryPolicy::class, 'restore']);
|
||||
|
||||
// products Policy
|
||||
Gate::define('products_viewAny', [ProductPolicy::class, 'viewAny']);
|
||||
Gate::define('products_viewAny_deleted', [ProductPolicy::class, 'viewAny_deleted']);
|
||||
Gate::define('products_view', [ProductPolicy::class, 'view']);
|
||||
Gate::define('products_create', [ProductPolicy::class, 'create']);
|
||||
Gate::define('products_edit', [ProductPolicy::class, 'edit']);
|
||||
Gate::define('products_delete', [ProductPolicy::class, 'delete']);
|
||||
Gate::define('products_delete_force', [ProductPolicy::class, 'delete_force']);
|
||||
Gate::define('products_restore', [ProductPolicy::class, 'restore']);
|
||||
Gate::define('products_amount_add', [ProductPolicy::class, 'amount_add']);
|
||||
Gate::define('products_amount_remove', [ProductPolicy::class, 'amount_remove']);
|
||||
|
||||
// cabel categories Policy
|
||||
Gate::define('cabelCategories_viewAny',[CabelcategoryPolicy::class,'viewAny']);
|
||||
Gate::define('cabelCategories_viewAny_deleted',[CabelcategoryPolicy::class,'viewAny_deleted']);
|
||||
Gate::define('cabelCategories_view',[CabelcategoryPolicy::class,'view']);
|
||||
Gate::define('cabelCategories_create',[CabelcategoryPolicy::class,'create']);
|
||||
Gate::define('cabelCategories_edit',[CabelcategoryPolicy::class,'edit']);
|
||||
Gate::define('cabelCategories_delete',[CabelcategoryPolicy::class,'delete']);
|
||||
Gate::define('cabelCategories_delete_force',[CabelcategoryPolicy::class,'delete_force']);
|
||||
Gate::define('cabelCategories_restore',[CabelcategoryPolicy::class,'restore']);
|
||||
|
||||
// cabels Policy
|
||||
Gate::define('cabels_viewAny',[CabelPolicy::class,'viewAny']);
|
||||
Gate::define('cabels_viewAny_deleted',[CabelPolicy::class,'viewAny_deleted']);
|
||||
Gate::define('cabels_view',[CabelPolicy::class,'view']);
|
||||
Gate::define('cabels_create',[CabelPolicy::class,'create']);
|
||||
Gate::define('cabels_edit',[CabelPolicy::class,'edit']);
|
||||
Gate::define('cabels_delete',[CabelPolicy::class,'delete']);
|
||||
Gate::define('cabels_delete_force',[CabelPolicy::class,'delete_force']);
|
||||
Gate::define('cabels_restore',[CabelPolicy::class,'restore']);
|
||||
Gate::define('cabels_amount_add',[CabelPolicy::class,'amount_add']);
|
||||
Gate::define('cabels_amount_remove',[CabelPolicy::class,'amount_remove']);
|
||||
|
||||
// loans Policy
|
||||
Gate::define('loans_viewAny',[LoanPolicy::class,'viewAny']);
|
||||
Gate::define('loans_create_user',[LoanPolicy::class,'create_user']);
|
||||
Gate::define('loans_create_laptop',[LoanPolicy::class,'create_laptop']);
|
||||
Gate::define('loans_adjust',[LoanPolicy::class,'adjust']);
|
||||
Gate::define('loans_return',[LoanPolicy::class,'return']);
|
||||
|
||||
// reservations
|
||||
Gate::define('reservations_viewAny',[ReservationPolicy::class,'viewAny']);
|
||||
Gate::define('reservations_create',[ReservationPolicy::class,'create']);
|
||||
Gate::define('reservations_validate',[ReservationPolicy::class,'validate']);
|
||||
Gate::define('reservations_cancel',[ReservationPolicy::class,'cancel']);
|
||||
Gate::define('reservations_setup',[ReservationPolicy::class,'setup']);
|
||||
Gate::define('reservations_pickup',[ReservationPolicy::class,'pickup']);
|
||||
Gate::define('reservations_extend',[ReservationPolicy::class,'extend']);
|
||||
Gate::define('reservations_return',[ReservationPolicy::class,'return']);
|
||||
|
||||
// notes
|
||||
Gate::define('notes_viewAny',[NotePolicy::class,'viewAny']);
|
||||
Gate::define('notes_viewAny_deleted',[NotePolicy::class,'viewAny_deleted']);
|
||||
Gate::define('notes_view',[NotePolicy::class,'view']);
|
||||
Gate::define('notes_create',[NotePolicy::class,'create']);
|
||||
Gate::define('notes_edit',[NotePolicy::class,'edit']);
|
||||
Gate::define('notes_delete',[NotePolicy::class,'delete']);
|
||||
Gate::define('notes_delete_force',[NotePolicy::class,'delete_force']);
|
||||
Gate::define('notes_restore',[NotePolicy::class,'restore']);
|
||||
|
||||
// Other
|
||||
Gate::define('home_page',[OtherPolicy::class,'home_page']);
|
||||
Gate::define('logs_viewAny',[OtherPolicy::class,'logs']);
|
||||
Gate::define('statistics',[OtherPolicy::class,'statistics']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldDiscoverEvents()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user