Guardian
  • Welcome
  • Getting Started
    • Installation
    • Getting a Guardian instance
    • Choosing an identifier
    • Firing off an HTTP request
  • Cache Stores
    • Cache Stores
    • Creating your own cache driver
    • Clearing the Cache
  • Rulesets and Rules
    • What are rulesets
    • Rate Limiting Rules
    • Error Handling Rules
  • Exceptions
    • RulePreventsExecutionException
    • IdentifierCannotBeEmptyException
    • RateLimitExceededException
    • StoreException
      • DatabaseStoreException
      • FileStoreException
      • RedisStoreException
Powered by GitBook
On this page
  • Requirements
  • Basic Installation
  • Framework Integration
  • Laravel Integration
  1. Getting Started

Installation

This PHP package is for PHP 8.2 and greater

Requirements

  • PHP 8.2 or higher

  • Composer

Basic Installation

You can install Guardian via Composer by running the following command in your project directory:

composer require midnite81/guardian

Framework Integration

While Guardian is framework-agnostic, it comes with built-in support for Laravel.

Laravel Integration

For Laravel projects, Guardian provides a Service Provider and a Facade, which are automatically registered in most cases.

Automatic Registration (Laravel 5.5+)

If you're using Laravel 5.5 or higher with package auto-discovery enabled, you don't need to manually register the service provider or facade.

Manual Registration

If you've disabled auto-discovery or are using an older version of Laravel, you'll need to manually register the service provider and facade.

For Laravel 11+:

Add the following to your bootstrap/app.php:

->withProviders([
    \Midnite81\Guardian\Providers\GuardianServiceProvider::class,
])

For Laravel 10 and below:

Add the following to your config/app.php:

'providers' => [
    // Other service providers...
    \Midnite81\Guardian\Providers\GuardianServiceProvider::class,
],

'aliases' => [
    // Other facades...
    'Guardian' => \Midnite81\Guardian\Facades\Guardian::class,
],
PreviousWelcomeNextGetting a Guardian instance

Last updated 7 months ago