LoginSignup
0
0

More than 5 years have passed since last update.

Laravel5.3

Posted at
  • Laravelのバージョン確認
php artisan --version
  • プロジェクトの作成
php composer.phar create-project --prefer-dist laravel/laravel <プロジェクト名>
  • データベースの作成
create database <データベース名>;
grant all on <データベース名>.* to <DBユーザ名>@localhost identified by '<DBパスワード>';
  • プロジェクトの初期設定
.env
DB_DATABASE=<データベース名>
DB_USERNAME=<DBユーザ名>
DB_PASSWORD=<DBパスワード>
config/app.php
'timezone' => 'Asia/Tokyo',
'locale' => 'ja',
  • テーブルの作成
php artisan make:migration create_<テーブル名>_table --create=<テーブル名>
database/migrations/create__table.php
    public function up()
    {
        Schema::create('<テーブル名>', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }
php artisan migrate
  • テーブルにカラムを追加する
php artisan make:migration add_<カラム名>_to_<テーブル名>_table --table=<テーブル名>
database/migrations/add__to__table.php
    public function up()
    {
        Schema::table('<テーブル名>', function (Blueprint $table) {
            $table->string('<カラム名>');
        });
    }

    public function down()
    {
        Schema::table('<テーブル名>', function (Blueprint $table) {
            $table->dropColumn('<カラム名>');
        });
    }
php artisan migrate
  • モデルの作成
php artisan make:model <モデル名>
app/.php
class <モデル名> extends Model
{
    protected $fillable = ['<カラム名1>', '<カラム名2>'];
}
  • レコードの追加
php artisan tinker

$row = new App\<モデル名>();
$row-><カラム名1> = '<カラム名1> 1';
$row-><カラム名2> = '<カラム名2> 2';
$row->save();

App\<モデル名>::create(['<カラム名1>'=>'<カラム名1> 2', '<カラム名2>'=>'<カラム名2> 2']);
App\<モデル名>::create(['<カラム名1>'=>'<カラム名1> 3', '<カラム名2>'=>'<カラム名2> 3']);

exit
  • ルートの設定
routes/web.php
Route::get('/', function() {
    return view('test');
});
resources/views/test.blade.php
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="utf-8">
    <title>test</title>
</head>
<body>
テストです
</body>
</html>
php artisan serve --host 192.168.33.10 --port 8000
  • スタイルの設定
resources/views/test.blade.php
    <link rel="stylesheet" href="css/styles.css">
public/css/styles.css
body {
    margin: 0;
    padding: 0;
    font-size: 16px;
    font-family: Verdata, sans-serif;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0