Skip to content

#4 Policy

php anonymous edited this page Aug 17, 2022 · 1 revision

Policies must be an essential factor for you when using them with the Gate

See this example

<?php
namespace Modules\Test\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;

class TestPolicy {
	use HandlesAuthorization;

	public function viewAny() {
		return true;
	}

	public function view() {
		return true;
	}

	public function create() {
		return true;
	}

	public function show() {
		return false;
	}

	public function update() {
		return true;
	}

	public function delete() {
		return true;
	}

	public function forceDelete() {
		return true;
	}

	public function restore() {
		return true;
	}
}

Just tell the lynx this policy in the controller and you don't have to go to activate the policy with the Model OR Entity

I think that the example is clear in front of you for each specific policy method, even forcible deletion, data retrieval, store, update, normal deletion, and even show method

You can create a policy along the lines of the general Laravel framework and support it and embed it in Lynx

namespace App\Polices;

use Illuminate\Auth\Access\HandlesAuthorization;

class TestPolicy {
	use HandlesAuthorization;

	public function viewAny() {
		return true;
	}

	public function view() {
		return true;
	}

	public function create() {
		return true;
	}

	public function show() {
		return false;
	}

	public function update() {
		return true;
	}

	public function delete() {
		return true;
	}

	public function forceDelete() {
		return true;
	}

	public function restore() {
		return true;
	}
}

See the embed here to see how the policies work with the controller Api@policy

Clone this wiki locally