vendredi 8 juin 2018

Small system of filtering users by their roles on laravel

I'm trying to implement a function in my controller to filter users of the application by their roles

My controller ProfileController.php has the following function:

     public function membrevis() {

    $filter = isset($_GET['filter']) ? $_GET['filter'] : null;


    $users = DB::table('users')
        ->join('user_role', 'user.id', '=', 'user_role.user_id')
        ->join('roles', 'users_roles.role_id', '=', 'roles.id')
        ->where('users.valid','=',0)
        ->select('users.*','roles.description');


       if($filter != null) {
        $users->where('users.name','like','%'.$filter.'%')
            ->orWhere('roles.description','like','%'.$filter.'%')
        }
               $users->get(); 
               return view('member2',['users'=> $users]);

             }

My view membre2.blade.php has the following HTML code:

               <form action="/membre2" method="get">
                  <input type="text" name="filter" >
                   <button type="submit">filter</button>
                                  </form>

The error i'm getting is:

     Parse error: syntax error, unexpected '}'

Any help would be appreciated!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire