invoiceninja/app/Http/Controllers/BaseController.php

45 lines
1.1 KiB
PHP
Raw Normal View History

2015-03-17 07:45:25 +10:00
<?php namespace App\Http\Controllers;
2016-03-15 19:08:00 -04:00
use App\Http\Middleware\PermissionsRequired;
2016-03-02 15:36:42 +02:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2016-04-25 21:53:39 -04:00
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2016-03-15 19:08:00 -04:00
use Auth;
2016-04-26 20:06:19 -04:00
use Utils;
2015-10-28 21:22:07 +02:00
2015-03-17 07:45:25 +10:00
class BaseController extends Controller
{
2016-04-25 21:53:39 -04:00
use DispatchesJobs, AuthorizesRequests;
2016-03-15 19:08:00 -04:00
2016-04-25 21:53:39 -04:00
protected $entity;
2015-10-28 21:22:07 +02:00
2015-03-17 07:45:25 +10:00
/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if (! is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
}
2016-03-15 19:08:00 -04:00
2016-04-25 21:53:39 -04:00
protected function authorizeCreate() {
$this->authorize('create', $this->entity);
}
2016-04-23 11:52:36 -04:00
protected function authorizeUpdate($input){
2016-03-15 19:08:00 -04:00
$creating = empty($input['public_id']) || $input['public_id'] == '-1';
if($creating){
2016-04-25 21:53:39 -04:00
$this->authorize('create', $this->entity);
2016-03-15 19:08:00 -04:00
}
else{
2016-04-26 20:06:19 -04:00
$className = Utils::getEntityName($this->entity);
2016-04-25 21:53:39 -04:00
$object = call_user_func(array("App\\Models\\{$className}", 'scope'), $input['public_id'])->firstOrFail();
2016-04-23 11:52:36 -04:00
$this->authorize('edit', $object);
2016-03-15 19:08:00 -04:00
}
2015-03-17 07:45:25 +10:00
}
}