jeudi 15 octobre 2015

Install script using Laravel models, possible?

I'm trying to write a small bash script that will talk to a simple PHP script, to setup new installations of our software. What I need to do is call various routes and access models, to create a system/default user etc.

So far I have -

Bash Script

#Set up variables
DIR="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
EMAIL="a@b.com"
PASSWORD="admin"
NAME="System User"

#Check command line args
if [ $# -gt 0 ] ; then
    while getopts ":e:p:n" opt; do
        case $opt in
        e)
                # Have email parameter
                echo "Overriding System User - Email"
                EMAIL=$OPTARG
            ;;

            p)
                echo "Overriding System User - Password"
                PASSWORD=$OPTARG
            ;;

            n)
                echo "Overriding System User - Name"
                NAME=$OPTARG
            ;;
        esac
    done
fi

echo "System Installer running"
php $DIR/install/create_user.php $EMAIL " " $PASSWORD " " $NAME

PHP

<?php

namespace App\Scripts\Install;

use App;
use App\Api\User\User;

$arg_email      = $argv[1];
$arg_password   = $argv[2];
$arg_name  = explode($argv[3], ' ');

$userObject = User::create([
    'firstname' => $arg_name[0],
    'lastname' => $arg_name[1],
    'email' => $arg_email,
    'password' => Hash::make($arg_password),
    'role' => 2,
    'digest_opt_in' => 1,
]);

My question is: Given this sort of flat-style php script, can I use Laravel models? (possibly jut import a different way?) - If so, what am I missing?

Cheers.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire