Laravel + Q&A Framework

1.7k views Asked by At

I'm most comfortable with Laravel and want to extend it with a Question and Answer framework such as Q2A or OSQA. How do I integrate the two together (ex. Q2A + Laravel)?

3

There are 3 answers

0
DisgruntledGoat On

OSQA uses a completely different language so that would be more difficult, to be honest. Q2A uses PHP like Laravel, but it's a standalone app and is its own framework in itself.

Q2A does however have a Single Sign On concept, so if you have users set up in Laravel they can integrate with Q2A. See the Q2A docs for more information.

0
Ateszki On

I've managed to run Q2A in Laravel install as a subfolder, this is what i did:

Install Question2Answer into laravel public/qa folder

Follow setup instructions form http://www.question2answer.org/single-sign-on.php

Add the followin function to public/qa/qa-external/qa-external-users.php

function laravelauth() {
      //modified from https://laracasts.com/discuss/channels/general-discussion/how-to-use-laravel-authuser-outside-laravel-and-pass-data-in-custom-php

      require getcwd() . '/../../bootstrap/autoload.php';
      $app = require_once getcwd() . '/../../bootstrap/app.php';

      $kernel = $app->make('Illuminate\Contracts\Http\Kernel');

      $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
      );

      $id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
      $app['session']->driver()->setId($id);
      $app['session']->driver()->start();

      if(!$app['auth']->check()) return ["is_loggedin"=>false];

      $salida = $app['auth']->user()->toArray();
      $salida["is_loggedin"] = true;

      return($salida);

    }

Then modify qa_get_logged_in_user() to

           $r = laravelauth();
            if($r["is_loggedin"]){

                            return array(
                                    'userid' => $r["id"],
                                    'publicusername' => $r["name"],
                                    'email' => $r['email'],
                                    'level' => QA_USER_LEVEL_BASIC //(select the level)
                            );
            }

You can select the User level based on the laravel user attributes or whatever you like.

0
pat On

How about creating a composer package, better yet, use the laravel workbench to create a laravel specific composer package?