Git Product home page Git Product logo

Comments (3)

williamcruzme avatar williamcruzme commented on June 4, 2024

Hello @N0SYS73M1SS4F3, you could try with:

async created() {
  const { data: permissions } = await this.$axios.get("/api/auth/permissions");
  const { data: roles } = await this.$axios.get("/api/auth/roles");

  this.$laravel.setPermissions(permissions);
  this.$laravel.setRoles(roles);
  console.log(permissions)
}

from vue-gates.

gladtoseeuhappy avatar gladtoseeuhappy commented on June 4, 2024

Hello @williamcruzme yes, i tried ur code, it work, Roles mounted, Permissions mounted,

but i try bind permission to User to See Sidebar base On Roles by implement like this

in My template

    <div v-for="(item, i) in menus" :key="i" router exact>
	<div v-if="$laravel.hasPermission(item.permission)">
		<template v-if="!item.children">
			<v-list-item :key="i" :to="item.to">
				<v-list-item-content>
					<v-list-item-title>
						<v-icon left>{{ item.icon }}</v-icon>
						{{ item.name }}
					</v-list-item-title>
				</v-list-item-content>
			</v-list-item>
		</template>

in my <script>

menus: [
	{
		name: "Dashboard",
		icon: "mdi-view-dashboard",
		to: "/",
		permission: "view users"
	},

When logged In, Every roles can see sidebar the same as Admin Role, Except Reload Pagee..

Is there a way to archieve it???
Sorry for ma bad English....

Edit: if i do my code like below, it work perfectly

created() {
	if (this.user.role[0] === "administrator") {
		this.$laravel.setPermissions("view users");
	}

	if (this.user.role[0] === "saleman") {
		this.$laravel.setPermissions([
			"view sales",
			"add sales",
			"edit sales",
			"delete sales",
			"import sales",
			"summary report",
			"product report",
			"daily sale report",
			"monthly sale report",
			"daily purchase report",
			"sale report",
			"purchase report",
			"warehouse report",
			"product qty alert",
			"customer report",
			"supplier report",
			"due report",
			"pos"
		]);
	}
}

from vue-gates.

williamcruzme avatar williamcruzme commented on June 4, 2024

Hi @N0SYS73M1SS4F3, thank you for your time.

Solution
Set the permissions/roles when you log in (before redirect), and enable persistent feature:

Vue.use(LaravelPermissions, { persistent: true });

Recommend solution
Work with Nuxt.js, you set the permissions/roles on the server side.

from vue-gates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.