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.
Related
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');
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
I am having a very weird issue when running
php artisan migrate
on a new installation of Laravel 5.4 on a local XAMPP server with php 7.1.1.
What it is doing is creating a migrations and users table, the default tables in older versions of Laravel. What is should be creating is a users table and a passwords reset table, the new default tables. My env file is correct because I am connecting to the database correctly but then if I change the table I am connecting to in the env file it is not updating.
To me, it seems like the command is simply not running on the correct migrations folder in the application. This is a brand new machine with a fresh install of XAMPP and Laravel so I am very confused as to why this is happening. Any help would be much appreciated!!!
I was finally able to get this to work so I wanted to answer the question to explain what I did.
This first step may not be required for you but it was for me. Once again, here is what I was using: Laravel 5.4 on a local XAMPP server with php 7.1.1
-First I needed to edit app>Providers>AppServiceProvider.php https://laravel-news.com/laravel-5-4-key-too-long-error
-Add this line to the top, under the other use include: use Illuminate\Support\Facades\Schema;
-In the boot() function add this code: Schema::defaultStringLength(191);
-After that I needed to run php artisan migrate, to create the default tables from the migrations. For some reason, a reason I could not find with any amount of research, this creates the old tables from an unknown source. After that I needed to edit the create_users_table migration, delete the users and migrations table that were created in the database, then rerun php artisan migrate. Like I said, I am not sure why this has to be done but it will get it to work.
Also, remember to run these commands before running php artisan migrate the last time just to be safe:
php artisan cache:clear
php artisan config:cache
php artisan migrate:refresh
php artisan migrate
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.
I'm trying to recover a project after a failed HDD. Lost the mysql information, so just have the project code.
I hoped to be able to put my database back together by using artisan migrate, but the error message tells me:
database.migrations doesn't exist
Is there actually a way I can use my Laravel code files and the command line to rebuilt my database like this?
Thanks for the help.
The command I needed to run was:
php artisan migrate:install
(I actually had more problems than this because the mysql install was messed up to. I don't know if simply php artisan migrate on its own would have implied :install but I'm adding it as an answer anyway should anyone have similar issues)