laravel 項目遷移
Before moving forward we need to know some facts about it,
在繼續前進之前,我們需要了解一些事實,
Resources: In these directories, we have already a js, lang, sass and view page. Where, sass and js file holf their uncompressed, unminified js, CSS, sass file.
資源:在這些目錄中,我們已經有一個js,lang,sass和view頁面。 sass和js文件將其未壓縮,最小化的js,CSS和sass文件分開。
view/welcome.blade.php: Which is already defined in storage/framwork/views/.... (at the bottom of the page: path/welcome.blade.php)
view / welcome.blade.php:已在storage / framwork / views / ....中定義(在頁面底部:path / welcome.blade.php)
在Laravel遷移 (Migration in Laravel)
We are creating migration for creating databases or Database columns in PHPMyAdmin or any other database. After migration it will be automatically creating a database in PHPMyAdmin means we don't have to create again database and it's columns in PHPMyAdmin.
我們正在創建遷移,以在PHPMyAdmin或任何其他數據庫中創建數據庫或Database列。 遷移后,它將自動在PHPMyAdmin中創建數據庫,這意味著我們不必再次創建數據庫,并且它是PHPMyAdmin中的列。
Here, we need to create a post-migration table for creating a table column to store, retrieve, edit and update the data, we can take columns name according to our requirement.
在這里,我們需要創建一個遷移后的表,以創建一個表列來存儲,檢索,編輯和更新數據,我們可以根據需要獲取列名。
First, On CMD run this command for creating a migration table,
首先,在CMD上運行此命令以創建遷移表,
$ php artisan make:migration create_posts_table
Now, you can see this migration file in this path and open it: database/migration/create_posts_table
現在,您可以在此路徑中看到此遷移文件并打開它: database / migration / create_posts_table
Here, I am declaring a column name in public function up{ // code }
在這里,我在public function up中聲明一個列名{//代碼}
Example: Code for create_posts_table
示例:create_posts_table的代碼
class CreatePostsTable extends Migration
{
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('posts');
}
}
public function up{}: In this function, we are creating a database schema. It is the blueprint of the table that's why we are writing a Blueprint $table in the Schema.
public function up {} :在此函數中,我們正在創建一個數據庫模式。 這就是表的藍圖,這就是我們在Schema中編寫Blueprint $ table的原因。
public function down{}: In this function, dropIfExists means to drop the table "posts" if already exists.
public function down {} :在此函數中, dropIfExists表示刪除表“ posts”(如果已存在)。
Now, again on CMD: $ php artisan migrate
現在,再次在CMD上: $ php artisan migration
Here, this command is used to migrate the table columns successfully. Every migration table has two classes "UP" and "down".
在此,此命令用于成功遷移表列。 每個遷移表都有兩個類“ UP”和“ down” 。
"UP" class: This method is used to set execution whenever the migration command is running.
“ UP”類 :每當運行遷移命令時,此方法用于設置執行。
"Down" class: This method is used to set when you want to rollback after migration. You can say that it is the reverse of the "UP" method.
“ Down”類 :此方法用于設置要在遷移后回滾的時間。 您可以說這與“ UP”方法相反。
Now, after migration, we have a new Posts table in PHPMyAdmin's blog' DB table named 'posts'. Again Here, "Posts" is your table name from where you can store, retrieve, delete and update your data.
現在,在遷移之后,我們在PHPMyAdmin的博客“ DB”表中有了一個名為“ posts”的新Posts表。 在這里, “職位”是您的表名,您可以在其中存儲,檢索,刪除和更新數據。
Now, here you can see after the migration database id automatically created in the PHPMyAdmin.
現在,在這里您可以看到在PHPMyAdmin中自動創建的遷移數據庫ID。
Conclusion:
結論:
In this article, we have learnt about the migration in Laravel. I hope you understood the concept, we will know more about it in the up coming articles. Have a great day! Happy Learning!
在本文中,我們了解了Laravel中的遷移 。 希望您理解這個概念,我們將在以后的文章中進一步了解它。 祝你有美好的一天! 學習愉快!
翻譯自: https://www.includehelp.com/laravel/migration.aspx
laravel 項目遷移