0

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.

laminatefish
  • 5,197
  • 5
  • 38
  • 70
  • It is not very clear for me what you want to achieve, can you give some more details? – Heto Oct 15 '15 at 13:50
  • For instance, you'll see above that I'm trying to create a User, using Laravel model. But so far unsuccessful. My question is, is it possible to use Laravel classes this way, without being in the envelope of $this->app. – laminatefish Oct 15 '15 at 13:54
  • https://laracasts.com/lessons/how-to-use-eloquent-outside-of-laravel and https://github.com/laracasts/Eloquent-Outside-of-Laravel – Ben Swinburne Oct 15 '15 at 13:56
  • Why not create the user direct in the database? – Heto Oct 15 '15 at 14:00

0 Answers0