$this->request->input("role") returns all request

81 Views Asked by At

I have this event to assign role:

  <?php

namespace App\Listeners\User;

use App\Events\User\Created;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Http\Request;
use Spatie\Permission\Traits\HasRoles;

class AssignRoles
{

    private $request;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     * Handle the event.
     *
     * @param  Created  $event
     * @return void
     */
    public function handle(Created $event)
    {
       $event->user;
       dd($this->request->get('role'));
        // here is the best place to do all the logic about roles that is going to be attached in this user. E.g:
        switch($role = $this->request->input('role')) 
        {

            case $role == 'Asesor':
                $event->user->assignRole('Asesor');
            break;
            case $role == 'Comprador':
                $event->user->assignRole('Comprador');
            break;
            default:
                $event->user->assignRole('Writer');
        }
    }
}

but Laravarel doesn't return only "input role", returns always all params in request ¿why?

this is the print message with command dd:

"_token=7WvSpLbPgRrQ570hcXRnUZiGUOUroXiFLFih1dTa&role=Asesor"

0

There are 0 best solutions below