2

I am using Laravel and sentinel to develop a permission system however it was designed so that the user can select and deselect which permissions the role has from a checkbox form. I have already coded the part where they can assign permissions however I need that the checkboxes that have already been assigned are marked when the user request the page. How do you recommend approaching this? I am using a middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;

class PermissionsMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    public function handle($request, Closure $next)
    {
        $user = Sentinel::findById(1);
        $permisos = array(array_keys($user['permissions']))

        return $next($request);
    }
}

However, I don't know how to pass data from the middleware to the view.

Amit Gupta
  • 17,072
  • 4
  • 41
  • 53
Mntfr
  • 483
  • 6
  • 20

1 Answers1

0

I don't think it's recommended using the middleware for this purpose, but if you still want to do it that way you can try using:

View::share ( 'permisos', $permisos );

To share the 'permisos' variable with the view that's coming after the middleware.

So your code is going to look like this:

<?php

namespace App\Http\Middleware;

use Closure;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;

class PermissionsMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    public function handle($request, Closure $next)
    {
        $user = Sentinel::findById(1);
        $permisos = array(array_keys($user['permissions']))
        View::share ( 'permisos', $permisos );

        return $next($request);
    }
}