Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
add-middleware
rhino-project/rhino-laravel
claude-code
middleware
http-requests
routing
crud-routes
laravel-middleware

Create a middleware and assign it to a model's CRUD routes. Use when the user wants to add logging, rate limiting, headers, validation, or any request/response processing to a model.

Install
php artisan boost:add-skill rhino-project/rhino-laravel

Save this content to: .claude/skills/add-middleware/SKILL.md

# Add Middleware

Creates a middleware class and assigns it to a model's CRUD routes via model properties.

## Workflow

### Step 1: Gather Requirements

Ask:
1. "What should the middleware do?" (log requests, add headers, rate limit, validate, etc.)
2. "Which model should it apply to?"
3. "Should it apply to all CRUD actions, or specific ones?"
   - All actions: goes in `$middleware`
   - Specific actions: goes in `$middlewareActions` with action names (`index`, `store`, `show`, `update`, `destroy`)

### Step 2: Generate Middleware

Create `app/Http/Middleware/{MiddlewareName}.php`:

```php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class {MiddlewareName}
{
    public function handle(Request $request, Closure $next): Response
    {
        // Pre-processing (before controller)

        $response = $next($request);

        // Post-processing (after controller)

        return $response;
    }
}
```

### Step 3: Assign to Model

**For all actions:**

```php
public static array $middleware = [
    \App\Http\Middleware\{MiddlewareName}::class,
];
```

**For specific actions:**

```php
public static array $middlewareActions = [
    'store'   => [\App\Http\Middleware\{MiddlewareName}::class],
    'update'  => [\App\Http\Middleware\{MiddlewareName}::class],
];
```

Both can be used together — `$middleware` applies to the route group, `$middlewareActions` adds on top per individual route.

### Step 4: Verify

Run `php artisan route:list` to confirm the middleware appears on the routes.

## Strict Rules

- NEVER put authorization logic in middleware (use Policies)
- NEVER put data filtering in middleware (use Scopes)
- NEVER register middleware in controller constructors
- Keep each middleware focused on ONE concern
- Always call `$next($request)` unless intentionally aborting the request

Add Middleware

Creates a middleware class and assigns it to a model's CRUD routes via model properties.

Workflow

Step 1: Gather Requirements

Ask:

  1. "What should the middleware do?" (log requests, add headers, rate limit, validate, etc.)
  2. "Which model should it apply to?"
  3. "Should it apply to all CRUD actions, or specific ones?"
    • All actions: goes in $middleware
    • Specific actions: goes in $middlewareActions with action names (index, store, show, update, destroy)

Step 2: Generate Middleware

Create app/Http/Middleware/{MiddlewareName}.php:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class {MiddlewareName}
{
    public function handle(Request $request, Closure $next): Response
    {
        // Pre-processing (before controller)

        $response = $next($request);

        // Post-processing (after controller)

        return $response;
    }
}

Step 3: Assign to Model

For all actions:

public static array $middleware = [
    \App\Http\Middleware\{MiddlewareName}::class,
];

For specific actions:

public static array $middlewareActions = [
    'store'   => [\App\Http\Middleware\{MiddlewareName}::class],
    'update'  => [\App\Http\Middleware\{MiddlewareName}::class],
];

Both can be used together — $middleware applies to the route group, $middlewareActions adds on top per individual route.

Step 4: Verify

Run php artisan route:list to confirm the middleware appears on the routes.

Strict Rules

  • NEVER put authorization logic in middleware (use Policies)
  • NEVER put data filtering in middleware (use Scopes)
  • NEVER register middleware in controller constructors
  • Keep each middleware focused on ONE concern
  • Always call $next($request) unless intentionally aborting the request
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle