0% found this document useful (0 votes)
16 views19 pages

Migration, Artisan, Seeder

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views19 pages

Migration, Artisan, Seeder

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Continuation to

Laravel
Artisan Console
Artisan is the command-line interface included with Laravel. It provides a number of
helpful commands that can assist you while you build your application. To view a list
of all available Artisan commands, you may use the list command:

php artisan list

Every command also includes a "help" screen which displays and describes the
command's available arguments and options. To view a help screen, precede the
name of the command with help:

php artisan help migrate


Artisan Command Usage
Usage:
command [options] [arguments]

Options:
-h, --help Display help for the given command. When no command is given
display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for
more verbose output and 3 for debug
Artisan Commands List
Available commands:
clear-compiled Remove the compiled class file
completion Dump the shell completion script
down Put the application into maintenance mode
env Display the current framework environment
help Display help for a command
inspire Display an inspiring quote
list List commands
migrate Run the database migrations
optimize Cache the framework bootstrap files
serve Serve the application on the PHP development server
test Run the application tests
tinker Interact with your application
ui Swap the front-end scaffolding for the application
up Bring the application out of maintenance mode
Artisan Commands List
auth
auth:clear-resets Flush expired password reset tokens
cache
cache:clear Flush the application cache
cache:forget Remove an item from the cache
cache:table Create a migration for the cache database table
config
config:cache Create a cache file for faster configuration loading
config:clear Remove the configuration cache file
db
db:seed Seed the database with records
db:wipe Drop all tables, views, and types
event
event:cache Discover and cache the application's events and listeners
event:clear Clear all cached events and listeners
event:generate Generate the missing events and listeners based on registration
event:list List the application's events and listeners
key
key:generate Set the application key
Artisan Commands List
make
make:cast Create a new custom Eloquent cast class
make:channel Create a new channel class
make:command Create a new Artisan command
make:component Create a new view component class
make:controller Create a new controller class
make:event Create a new event class
make:exception Create a new custom exception class
make:factory Create a new model factory
make:job Create a new job class
make:listener Create a new event listener class
make:mail Create a new email class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:notification Create a new notification class
make:observer Create a new observer class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:resource Create a new resource
make:rule Create a new validation rule
make:seeder Create a new seeder class
make:test Create a new test class
Artisan Commands List
migrate
migrate:fresh Drop all tables and re-run all migrations
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
notifications
notifications:table Create a migration for the notifications table
optimize
optimize:clear Remove the cached bootstrap files
package
package:discover Rebuild the cached package manifest
route
route:cache Create a route cache file for faster route registration
route:clear Remove the route cache file
route:list List all registered routes session
session:table Create a migration for the session database table
storage
storage:link Create the symbolic links configured for the application
ui
ui:auth Scaffold basic login and registration views and routes
ui:controllers Scaffold the authentication controllers
Artisan Commands List

vendor
vendor:publish Publish any publishable assets from vendor packages
view
view:cache Compile all of the application's Blade templates
view:clear Clear all compiled view files
Database: Migration
Migrations are like version control for your database, allowing your team to modify and share the application's
database schema. Migrations are typically paired with Laravel's schema builder to build your application's
database schema. If you have ever had to tell a teammate to manually add a column to their local database
schema, you've faced the problem that database migrations solve.

The new migration will be placed in your database/migrations directory. Each migration file name contains a
timestamp, which allows Laravel to determine the order of the migrations.
Database: Migration
The --table and --create options may also be used to indicate the name of the table and whether or not the
migration will be creating a new table. These options pre-fill the generated migration stub file with the specified
table:

If you would like to specify a custom output path for the generated migration, you may use the --path option
when executing the make:migration command. The given path should be relative to your application's base
path.
Migration Structure
A migration class contains two methods: up and down. The up method is used to add new tables, columns, or
indexes to your database, while the down method should reverse the operations performed by the up method.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFlightsTable extends Migration


{
public function up()
{
Schema::create('flights', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('airline');
$table->timestamps();
});
}

public function down()


{
Schema::drop('flights');
}
}
Migration Structure
You may use the following commands on the schema builder to define the table's options:
Migration: Creating Columns
The table method on the Schema facade may be used to update existing tables. Like the create
method, the table method accepts two arguments: the name of the table and a Closure that
receives a Blueprint instance you may use to add columns to the table:
Migration:
Available
Column Types
Migration: Available Column Types
Link: https://laravel.com/docs/7.x/migrations#creating-columns
Eloquent
Eloquent
Eloquent
Note that we did not tell Eloquent which table to use for our Flight model. By
convention, the "snake case", plural name of the class will be used as the table
name unless another name is explicitly specified. So, in this case, Eloquent will
assume the Flight model stores records in the flights table. You may specify a
custom table by defining a table property on your model:

const CREATED_AT = 'creation_date';


const UPDATED_AT = 'last_update’;
public $timestamps = false;
public $incrementing = false;
protected $primaryKey = 'flight_id’;
protected $table = 'my_flights';

You might also like