Skip to content

Instantly share code, notes, and snippets.

@atrakeur
Created January 23, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrakeur/8aca9eb473853b206e33 to your computer and use it in GitHub Desktop.
Save atrakeur/8aca9eb473853b206e33 to your computer and use it in GitHub Desktop.
Laravel database installation script
<?php
use Symfony\Component\Console\Output\BufferedOutput;
class InstallController extends BaseController {
public function index($user, $pass)
{
//check trivial pour éviter les reset intenpestifs
//a vous d'implemnter votre propre méthode de verrification
if ($user != "MonUser" || $pass != "MonPass")
{
exit;
}
//redirige STDIN pour capturer la sortie de la commande
define('STDIN', fopen("php://stdin","r"));
$output = new BufferedOutput;
if (!Schema::hasTable('migrations'))
{
Artisan::call('migrate:install', array(), $output);
}
//Met a jour les migrations, puis seed la base avec le jeu de départ
Artisan::call('migrate:refresh', array('--force' => 1), $output);
Artisan::call('db:seed', array('--force' => 1), $output);
$messages = explode("\n", trim($output->fetch()));
//affiche la sortie en json
echo json_encode(array('messages' => $messages));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment