本文整理汇总了PHP中Illuminate\Support\Facades\Gate类的典型用法代码示例。如果您正苦于以下问题:PHP Gate类的具体用法?PHP Gate怎么用?PHP Gate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
if (Gate::denies('addClient', new Client())) {
abort(403, 'Not allowed');
}
return View::make('client.create');
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Gate::denies('contributor')) {
abort(403);
}
return $next($request);
}
示例3: boot
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Gate::define('administer', function (User $user) {
return $user->roles->contains('name', 'admin');
});
}
示例4: update
/**
* updates activity sector
* @param $id
* @param Request $request
* @param SectorRequestManager $sectorRequestManager
* @return \Illuminate\Http\RedirectResponse
*/
public function update($id, Request $request, SectorRequestManager $sectorRequestManager)
{
$activityData = $this->activityManager->getActivityData($id);
if (Gate::denies('ownership', $activityData)) {
return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
}
$this->authorizeByRequestType($activityData, 'sector');
$sectors = $request->all();
foreach ($sectors['sector'] as &$sector) {
if ($sector['sector_vocabulary'] == 1 || $sector['sector_vocabulary'] == '') {
$sector['sector_vocabulary'] = 1;
$sector['sector_category_code'] = '';
$sector['sector_text'] = '';
} elseif ($sector['sector_vocabulary'] == 2) {
$sector['sector_code'] = '';
$sector['sector_text'] = '';
} else {
$sector['sector_code'] = '';
$sector['sector_category_code'] = '';
}
}
if ($this->sectorManager->update($sectors, $activityData)) {
$this->activityManager->resetActivityWorkflow($id);
$response = ['type' => 'success', 'code' => ['updated', ['name' => 'Sector']]];
return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
}
$response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Sector']]];
return redirect()->back()->withInput()->withResponse($response);
}
示例5: destroy
/**
* @param $id
* @return int
*/
public function destroy($id)
{
if (Gate::denies('manage-users')) {
abort(403, 'You dont have permissions!!');
}
return (int) $this->usersRepo->delete($this->usersRepo->byId($id));
}
示例6: destroy
public function destroy($id)
{
if (Gate::denies('managerOnly')) {
abort(403);
}
return Group::destroy($id);
}
示例7: update
/**
* updates activity recipient region
* @param $id
* @param Request $request
* @param RecipientRegionRequestManager $recipientRegionRequestManager
* @return \Illuminate\Http\RedirectResponse
*/
public function update($id, Request $request, RecipientRegionRequestManager $recipientRegionRequestManager)
{
$activityData = $this->activityManager->getActivityData($id);
if (Gate::denies('ownership', $activityData)) {
return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
}
$this->authorizeByRequestType($activityData, 'recipient_region');
$activityTransactions = $this->transactionManager->getTransactions($id);
$count = 0;
if ($activityTransactions) {
foreach ($activityTransactions as $transactions) {
$transactionDetail = $transactions->transaction;
removeEmptyValues($transactionDetail);
if (!empty($transactionDetail['recipient_country']) || !empty($transactionDetail['recipient_region'])) {
$count++;
}
}
}
if ($count > 0) {
$response = ['type' => 'warning', 'code' => ['message', ['message' => 'You cannot save Recipient Region in activity level because you have already saved recipient country or region in transaction level.']]];
return redirect()->back()->withInput()->withResponse($response);
}
$recipientRegions = $request->all();
foreach ($recipientRegions['recipient_region'] as &$recipientRegion) {
$recipientRegion['region_vocabulary'] != '' ?: ($recipientRegion['region_vocabulary'] = '1');
}
if ($this->recipientRegionManager->update($recipientRegions, $activityData)) {
$this->activityManager->resetActivityWorkflow($id);
$response = ['type' => 'success', 'code' => ['updated', ['name' => 'Recipient Region']]];
return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
}
$response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Recipient Region']]];
return redirect()->back()->withInput()->withResponse($response);
}
示例8: destroy
public function destroy($id)
{
if (Gate::denies('adminOnly')) {
abort(403);
}
return Organization::destroy($id);
}
示例9: __construct
/**
* Create a new controller instance.
* @internal param ReflectionClass $reflect
*/
public function __construct()
{
if (get_sparkplug_config('ACL')) {
if (Gate::denies(get_module_class_name($this))) {
abort('403', 'User has no privilages to access this page');
}
}
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Gate::denies('authorization', $request->route()[1]['uses'])) {
abort(403);
} else {
return $next($request);
}
}
示例11: show
/**
* Show Dashboard.
*
* @return mixed
*/
public function show()
{
$content = Content::newPostInstance();
if (Gate::denies('create', $content)) {
return view('orchestra/story::admin.home');
}
return $this->writePost($content);
}
示例12: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::findOrFail($id);
if (Gate::denies('update', $post)) {
abort(403, 'no fucking way bitch');
}
return $post->title;
}
示例13: update
public function update(Request $request, PersonModel $person)
{
$person->setName($request->input('name'))->setEnabled($request->has('enabled'));
if (Gate::allows('editSuperuser', $person)) {
$person->setSuperuser($request->has('superuser'));
}
PersonFacade::save($person);
}
示例14: managerIndex
public function managerIndex()
{
if (Gate::denies('managerOnly')) {
abort(403);
}
// Retrieve all the users defined for the organization of the currently authenticated manager
return Auth::user()->organization->users;
}
示例15: coverStore
public function coverStore(Request $request, $id)
{
$book = Book::find($id);
if (Gate::denies('manageBook', $book)) {
abort(403, 'voce não é o dono desse livro');
}
$bookService = app()->make(BookService::class);
$bookService->storeCover($book, $request->file('file'));
}