Run php artisan command in out of laravel project - php

I am writing an installer for laravel project.
but for some reason, I don't run this installer from laravel project.
I use PHP code. I want to use php artisan migrate on my installer and I know that I can use this command system("php artisan migrate") but I don't want to use system functions on my installer. Is there any way to artisan command on PHP out of laravel?

Unfortunately artisan is baked into the Laravel Framework so your options are limited but you still have options.
Use the Spatie laravel-migrate-fresh package (be sure to read before use)
This would be suitable for a fresh install process
Use a shell script for your build
You can easily incorporate a shell script to run your migrations
Roll your own installer using Symfony's console
Vivek Kumar Bansal provides a good article on his Blog to do just this
Create a standalone installer using Laravel
This can contain your migrations and other commands (with input if you like)
Nuno Maduros Laravel Zero could actually be perfect for you!
It has migrations built in

You can use php's exec() function.
http://php.net/manual/en/function.exec.php
exec('php artisan migrate');

Related

How to run artisan outside of Laravel?

Is it possible to run Artisan commands from a script that is not part of Laravel?
How can I import artisan into my script?
<?php
Artisan::call('some:command');
This script will is not part of Laravel and just a regular old php file. My question is, how can I import Artisan into my script?
My final goal, is to automate the installation of my app, I need to run a migrations, seeds and a couple other things.
Unfortunately, you cannot use artisan without Laravel as it is not a stand-alone package and requires the full Laravel framework.
However, Artisan is based on the Symfony Console package which can be added to your script as a stand-alone package, which is the closest you will get to Artisan without writing a custom bash script.
http://symfony.com/doc/current/components/console.html

What is the difference between artisan and composer from the point view of a laravel project?

I didn't know composer before laravel and i encountered them at the same time. So, I can't distinguish the commands of them, but memorize them.
What is the difference between php artisan and composer.phar and also the commands they run?
Can anyone help me on this issue? Thanks..
Composer is a package manager for php and artisan is a command line tool using php
Composer
- download libraries
Artisan
- run scripted commands like you would in bash
The reason to use artisan instead of direct php commands is that you have to implement certain functions so you get an universal feel to the commands. It will help with a lot of things like handling arguments. You could see it as a nice helper for writing great php command line tools.
Once your command is generated, you should fill out the name and
description properties of the class, which will be used when
displaying your command on the list screen.
The fire method will be called when your command is executed. You may
place any command logic in this method.
https://laravel.com/docs/5.0/commands
There is a basic difference in these two commands that they belongs to two different packages.
Composer: composer is a dependency management tool for php. It auto manages dependencies of your project according to your requirements and thus makes your project more distributable.
You don't have to package all the dependencies inside your application. And, if your dependencies are variable it is hard to manage them all within your application. So, composer does it for you.
So, your composer command operates this package. And, it can be used for any project whether it is laravel or other php application.
Artisan: This is the command line utility of Laravel. It comes integrated with your laravel installation.
You can perform operations on your laravel project using its commands. As it is a tool built over php. So, you need to execute its command over php-CLI. That is why you use the php before it.
And, you need to use artisan before it because this is the script name which operates the commands of this tool. If you see your laravel project directory it has a file named artisan inside the root folder. It is the file which bootstraps the laravel's command line code. Or, you can say it is like index.php of directory.
Hope I was helpful.

Best way to create console commands in php that alias a composer package command?

I am creating a php framework and am using various other libraries. Some of which come with commands that must be run like so
vendor/bin/phinx migrate
my question is, how do I somehow alias these commands so instead of typing in
vendor/bin/phinx migrate
I can type
php something-here migrate
kind of like how the Laravel framework does it with
php artisan migrate
I have tried making a file called something-here and using a switch statement on $argv and checking the case for $argv[1] and using echo shell_exec('vendor/bin/phinx migrate') this works but I think there must be a better way, and i can imagine this is not the most secure way. and maybe possibly I can retain the terminal colors? Just to be clear I am using composer.
Question is a little old, but might still be worth to answer.
This answer is for linux only and you need to edit your bash-shell.
Open the file ~/.bashrc and at the end of the file, add te following line:
alias phinx='vendor/bin/phinx'
Save the file and install it.
$ source ~/.bashrc
Now you can use the phinx command like:
$ phinx migrate

Using Illuminate Database outside Laravel without PHP Artisan Commands

I'm trying to set up database migrations using Illuminate's Database outside of a Laravel 4.2 project. Everything I'm reading online indicated that it is completely doable to use any Illuminate components outside of Laravel, but the difficulty I'm having is creating the database migrations without using Artisan commands ("php artisan make:migration create_user_table"). If any one could help me out with this, I'd really appreciate it, because I know someone has had to find a solution to the problem before.
Thanks!
If you want to use artisan commands you should include the package of it and configure your application accordingly.
illuminate\database package doesn't provide you and artisan commands to use.

How to clear the Laravel Application Key via Terminal

I'm creating a application. I want to clear the Laravel Application key via terminal. Not manually.
Is there any way to clear via artisan. I can only generate via following command
php artisan key:generate
But there is no option to delete the key via artisan command.
There's no way as I of right now I believe, but if you use git just fork laravel, go ahead and empty the application key and whenever starting a new Laravel project clone from your repo and just generate a key without editing anything.
I see that you're using Ubuntu, but just so you know there is a OSX extension for Alfred for creating Laravel projects here and comes with Jeffrey Way's Generator.

Categories