I am new to laravel. i know command to create database from laravel migration.
I have already created database in mysql. so how can i convert migration from that database.
You could use Jeffrey Way's generator tool for Laravel 4, and do them by hand. It is a very useful tool. https://github.com/JeffreyWay/Laravel-4-Generators (if you are using Laravel 5, use this package instead: https://github.com/laracasts/Laravel-5-Generators-Extended)
Or you could try out one of the following packages, they should convert your existing schema to Laravel migrations. I have not tried them, but have a look:
https://github.com/adamkearsley/laravel-convert-migrations
https://github.com/barryvdh/laravel-migration-generator
Also, read the following answer in another question, might be useful to you or others: Reverse engineering or Auto-Generations of Entities in Laravel?
For modern versions of Laravel you should probably use a package like https://github.com/kitloong/laravel-migrations-generator
I quick wrote this python script to make migration files out of an existing database.
https://github.com/aljorhythm/sql-to-laravel-migrations
After set up, just do
python retrieve-and-convert.py
If the accepted answer (at the time of editing this post) does not work for you, use this simple approach.
Check out this package by Kitloong is really easy to use.
https://github.com/kitloong/laravel-migrations-generator
After installation, just run something like this to export the migration to a location of your choice:
php artisan migrate:generate --path="path\to\existing\folder"
Example:
php artisan migrate:generate --path="C:\xampp\htdocs\laravel_bs4\database\migrations\my_new_migrations"
You should end up with migrations created from the database and saved in the location you have specified.
You can omit the --path option and simply run
php artisan migrate:generate
This would export it to the default Laravel's migration folder (which is something I usually do not want).
Be sure to follow the prompts. Sticking to the default is usually okay.
How about this?
Migrations Generator.It's for Laravel, 4, 5, 6, 7, but I don't know if it is for Laravel 8
Simple solution, to use online Laravel migration generator for your existing SQL table schema without installing any package. Just enter your SQL schema and get Laravel migration file.
Try: https://laravelarticle.com/laravel-migration-generator-online
If you don't mind using Doctrine 2 in your project instead of Eloquent that has reverse engineering built in.
For laravel 9 follow below link
https://laravel.com/docs/9.x/migrations#generating-migrations
Related
I want to change the default directory for creating migration i.e. If I do php artisan make:migration create_users_table, it should create users table in /database/migrations/child_database. I do not want to use --path every time I create a migration for child_database. I want to change the default directory for php artisan make:migration.
you can create your own artisan command to achieve this:
create your a new artisan command and use it to make migration in your custom directory using this article. hope help you ^_^
try this package github repo or use laracast link
You can use loadMigrationsFrom() in your AppServiceProvider.
Inside the boot() function, run:
/**
* Register Custom Migration Paths
*/
$this->loadMigrationsFrom([
database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder1',
database_path().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'folder2',
]);/
This question has been answered before, even though it's a little bit old it still has it's value.
Have a look at: https://stackoverflow.com/a/35895106
If you use this answer, the default directory is changed and you will have the solution you want.
I want to use avatar in my faker users seeding and I try to use https://github.com/ottaviano/faker-gravatar
But I got error trying to install it :
[InvalidArgumentException]
Package ottaviano/faker-gravatar has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version:
- ottaviano/faker-gravatar 0.1.2 requires php ^7.1 which does not match your installed version 8.1.0.
Looks like it does not support php 8...
Are there similar pluging supporting php 8 ?
Or maybe I can tune this plugin to work under php 8?
Thanks in advance!
You could create an issue on the repo and request that the maintainer update the package to support PHP 8. Alternatively you could fork the repo and either maintain that fork yourself, or create a pull request once you've updated the package.
With the above in mind though, something to note is that package is using an abandoned faker library. There is a new fork that is recommended for use but does not have a gravatar provider.
You could write your own provider for the newer faker library or alternatively go down the very simple route of just implementing a statement to generate a gravatar yourself.
'https://www.gravatar.com/avatar/' . md5(strtolower(trim($faker->email()))) . '?d=identicon';
The above will look for an existing gravatar for the provided email address and return that if it finds one, otherwise will return a default gravatar image which in my example is a geometric pattern based on the email hash.
Whilst this solution might not be as flexible as the package in your question, if all you're after is a gravatar and don't care whether it's isometric or a robot (see default images in the API docs for changing the default image generated) then something simple like this might be all you need.
I am new in Laravel and want to know such problem
I am running an web application on several server using Laravel.
But I have encountered with an issue.
When there is modification for the project, I need to sync with git on several servers.
But it has different settings for each server (eg: DB name, DB password...)
I have set it manually because I couldn't use .env or configuration file since the file is just pure php file.
The issue I want to solve is how can I get Laravel configuration data from pure PHP file(not controller or whatever).
It will be thankful if someone teach me solution.
You asked:
how can I get Laravel configuration data from pure PHP file
The answer would be this:
You just make some file in config/ folder of laravel app (or use the existing file like config/app.php)
You make an array of your key value pairs
<?php
return [
'some_key' => 'some_value',
...
and you simply call it with this code where ever you need it:
config('config_file.key');
for example
config('app.name');
would give you Laravel by default.
I have a fresh Laravel installation and I've added Cashier to my project.
Since the Users model on my app won't have a stripe connection, but rather an Accounts model, I need to alter their migration to add columns to Accounts instead of Users
The documentation says to run:
php artisan vendor:publish --tag="cashier-migrations"
which adds the two migration files to database/migrations
From there I can change users to accounts in the migration file.
When I try to run php artisan migrate, I get:
Whoops\Exception\ErrorException : Cannot declare class CreateCustomerColumns, because the name is already in use
This problem only goes away when I delete the migration files, but then the new columns are added to users.
The documentation states that you can disable their migration files by putting Cashier::ignoreMigrations(); in AppServiceProvider
I didn't realize that's what I wanted to do. I thought the publish command only published the two files I needed to edit, however, those are the only migration files that come with Cashier.
Be sure to add Cashier::ignoreMigrations(); in the register method.
And add use Laravel\Cashier\Cashier;
The file (and thus the class) must exist twice, probably in your database/migrations directory, most likely with 2 different datetime prefixes on the filenames.
I'm working on a Laravel project and I'm using https://laravel.com/docs/5.3/scout with ElasticSearch on a model Offer.
With the command php artisan scout:import "App\Models\Offer" I can generate an index for ElasticSearch with offers from my database, and it's ok. After that I can search offers in this index.
But now, I removed somes offers from my database, and I don't know how can I reset or re-generate the index for remove old ids ?
For example I removed Offer with id = 15 in my database, but when I do a search, this offer (id=15) is always indexed, and I get an error because this offer doesn't exist.
I tried to re run the command scout:import but no effect. The only solution I fond is to rename the index with https://laravel.com/docs/master/scout#configuring-model-indexes but I can't do that each times...
Any ideas ?
You can use php artisan scout:flush "App\Models\Offer"
You can also remove physical files for indexes from storage folder
The driver should automatically remove/update the record when you do a remove/update on any Model declared as Searchable.
To flush the models use: php artisan scout:import Model
You could check the bugs area for laravel-scout, maybe there is something related or try an update to L5.4