Code Monkey home page Code Monkey logo

laravelranks's Introduction

Laravel Custom Rank Middleware

Installation

  1. Drag all folders inside the LaravelRanks folder into the root of your Laravel project

  2. Change the ranks that you want to have in database\seeders\RankSeeder.php 2.1 (Optional) Customize ranks by adding an array and changing RankName and RankValue to what you want.

     [
     'rankName'  => 'RankName',
     'rankValue' => RankValue,
     ],
    
  3. In app\Http\Kernel.php add 'rank' => \App\Http\Middleware\RankChecker::class, at the bottom of $routeMiddleware.

  4. Add 'rank', to $fillable in user.php.

  5. Add the following to user.php public function rank() { return $this->hasOne(UserRanks::class); }

  6. Add $rank = !User::count() ? 999 : 1; in RegistrationController.php after you validate the filled in form details.

  7. Add 'rank' => $rank to your User::create for example: User::create([ 'name' => $request->name, 'username' => $request->username, 'email' => $request->email, 'password' => Hash::make($request->password), 'rank' => $rank ])->sendEmailVerificationNotification();

  8. Run php artisan migrate.

  9. Run php artisan db:seed -class=RankSeeder

Usage

You can authorize a rank to access a route by adding them to the middleware() like this:

public function __construct() {
    $this->middleware(['rank:Admin']);
}

Or if you want multiple ranks to be able to access a route:

public function __construct() {
    $this->middleware(['rank:Admin,Moderator']);
}

laravelranks's People

Contributors

mrgoatsy avatar

Watchers

 avatar

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.