Weave Code
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

Strong Parameters Bundle Laravel Package

domingollanes/strong-parameters-bundle

View on GitHub
Deep Wiki
Context7

Strong Parameters Bundle

This bundle allow to simulate Strong Parameters from Rails, inside Symfony Controllers.

You can simply allow and deny items from parameters.

This bundle is really useful for APIs, but can be used in any application.

ALERT: this is an early version.

Tested only in Symfony 3.4.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require domingollanes/strong-parameters-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new DomingoLlanes\StrongParametersBundle\StrongParametersBundle(),
        );

        // ...
    }

    // ...
}

Configuration

The bundle accepts two configurations, you can override them in config.yml. But it have defaults values.

// config.yml

strong_parameters:
  resource: '%kernel.project_dir%/app/Resources/parameters/'
  exceptions: false

Configuring the permitted parameters

You can easily configure namespaces of permitted parameters, for example:

// app/Resources/parameters/user.yml

allow:
  test:
  test2:
    test1:
      t3:
      t2:
deny:
  - test4

That yaml accepts this parameters in Controller action:

array:2 [
  "test" => "testValue"
  "test2" => array:1 [
    "test1" => array:2 [
      "t2" => "t2Value",
      "t3" => "t3Value"
    ]
  ]
]

How to use


// src/AppBundle/Controller/DefaultController.php

// ...

    public function testAction(Request $request, ParametersService $parametersService)
    {
        // ...

        // For $_GET parameters
        $params = $parametersService->permitParameters('user', $request->query->all());

        // For $_POST parameters
        $params = $parametersService->permitParameters('user', $request->request->all());

        // For Content/json parameters
        $params = $parametersService->permitParameters('user', json_decode($request->getContent(), true));
        // ...
    }
    
// ...

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui