I am developing a package for an application with Laravel 4, I added some seeders into the folder seeds of folder database of my application, what is the right command line to run the seeder ?
I tried some similar commands to db:migrate to run these seeders like:
php artisan db:seed --package=Packagename/PackageDirectory
but it seems they are not working here, what is the right command line to run these seeders insdie the package from root of application?
According to the documentation, the only available option for this function is --class.
What you can do is create a class that gets data from your package.
Related
Is it possible to create schemas automatically in the database when xampp is turning on? There is no information about it in the Laravel documentation, documentation says only how to do it manually by writing the command php artisan migrate.
Xampp includes a script called apache_startup.bat in the root directory, you can add the following line to it
c:\xampp\php\php.exe -f /path/to/laravel/app/artisan migrate
Then when the apache server starts, it should run that the equivalent of php artisan migrate to setup the database.
You can do php artisan make:migration [migration-name] - other than that, you have to fill the rest yourself.
I have a long list of migration files and don't want to compare what already ran and what is suppopsed to run next time when I do
php artisan migrate
Is there a way how to display such list ( without actually installing new 3rd party package)?
Better user php artisan migrate:status
This will basically show you the migrations which have been run and which are pending as well
You can use php artisan migrate --pretend to dump a list of all database queries that would be ran if you would migrate. But there is no command to list the migration files that would be executed.
It is not mentioned in the docs and in the CLI help, it says - Creates the Migration Repository.
What does that mean?
When I run thus command it says - database laravel not found.
Laravel creates a migrations table in your database to keep track of what migrations have already been ran on your database. If you run php artisan migrate:install, this table is created.
This table makes sure that when you run php artisan migrate, migrations that have already been ran on the database are not done again.
When migrating, this table is also created automatically, there is no need to run the install command beforehand.
The reason for your error is probably because you have not set the correct database credentials in either your .env file or config/database.php file.
I installed laravel passport using command compser require laravel/passsport,
but after this, no new migration was made in database/migrations directory.
Why is that?
The migration files exist in the Passport package in your vendor directory.
The migrations won't be copied over to your database/migrations folder as they don't need to be since they're registered by the PassportServiceProvider.
You should just be able to run php artisan migrate and they will be included.
If you're using Laravel 5.3 or 5.4 then you will need to register the service provide in your app/config.php file.
If you want to modify passport migration or just want it inside your migrations folder you can publish passport migrations files to your migrations folder using publish command:
php artisan vendor:publish --tag=passport-migrations
Make sure you have PassportServiceProvider registered in config/app.php
// config/app.php
Laravel\Passport\PassportServiceProvider::class,
You can also delete from migrations table specific migration(s). Running php artisan migrate again should recreate specific migrations only.
I just installed Cartalyst's Sentry 2 in a Laravel 4 application but I found out that I have to run that package's migrations separately by specifying --package=cartalyst/sentry, which makes automatic deployment impossible.
Is there a way to run php artisan migrate and have it run Sentry's migrations as well?
After Laravel 5 there is a better way to solve this:
Create your migrations in package's
/database/migrations folder
.
After that, in package's service provider create a boot method, referencing the migrations folder
public function boot()
{
$this->loadMigrationsFrom(__DIR__ .
'/database/migrations');
}
Now, on the top level folder (the main app, which required this package), you can run the default migrate command ( php artisan migrate ) and it will automatically find the packages migrations througth the loadMigrationsFrom method
ANSWER COPIED FROM:
http://voerro.com/en/tutorials/r/developing-and-distributing-laravel-5-packages/3
What I usually do in a scenario like this is publish the package migrations though the command:
php artisan migrate:publish vendor/package
This copies the migration files from any given package to your migrations folder.
I created a composer script to replace php artisan migrate ...... The script runs my migrations and the vendor's migrations everything at once.
My composer scripts is
"scripts": {
"migrate": [
"php artisan migrate --env=$LARAVEL_ENV",
"php artisan migrate --package=\"cartalyst/sentry\" --env=$LARAVEL_ENV",
"php artisan migrate --package=\"mrjuliuss/syntara\" --env=$LARAVEL_ENV",
"php artisan migrate --package=\"filmoteca/static-pages\" --env=$LARAVEL_ENV"
]
}
Then you can run the migration with LARAVEL_ENV=prod composer run-script migrate
To pass parameter to the script I use environment variables. In the previous example I set the environment variable LARAVEL_ENV to prod so the migration use the production database connection.
You can always create a alias in your local machine to short the command. For example alias migrate="LARAVEL_ENV=local composer run-script migrate"
I think this approach is good because when you are going to add a new package to your composer.json and this package has a migration you add the package and the package's migration in the same file. So, you do not forget add/remove the migration of a package.
This is a complete composer.json with the script
The 3rd party package must declare a Service Provider, that declare migrations.
As you can see at https://github.com/laravel/passport/blob/9.x/src/PassportServiceProvider.php#L80:
protected function registerMigrations()
{
if (Passport::$runsMigrations && ! config('passport.client_uuids')) {
return $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
}