Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature migration #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class CategoryController extends Controller
{
public function index(Category $category)
{
return view('categories.index')->with(['posts' => $category->getByCategory()]);
return view('Categories.index')->with(['posts' => $category->getByCategory()]);
}
}
2 changes: 1 addition & 1 deletion app/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getPaginateByLimit(int $limit_count = 5)
return $this::with('category')->orderBy('updated_at', 'DESC')->paginate($limit_count);
}

public function category()
public function weather()
{
return $this->belongsTo('App\Category');
}
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/2022_03_23_210057_create_posts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title', 50); //タイトル
$table->string('body', 200); //本文
$table->string('text', 200); //本文
$table->timestamps();
$table->softDeletes();
$table->integer('weather_id')->unsigned();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

class AddWeatherIdColumnToPostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
//
$table->integer('weather_id')->unsigned();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('posts', function (Blueprint $table) {
//
});
}
}
35 changes: 35 additions & 0 deletions database/migrations/2022_06_04_213639_create_flowers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

class CreateFlowersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flowers', function (Blueprint $table) {
$table->increments('id');
$table->string('flower_name');
$table->string('flower_image');
$table->integer('weather_id')->unsigned();
$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('flowers');
}
}
33 changes: 33 additions & 0 deletions database/migrations/2022_06_04_213712_create_weathers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

class CreateWeathersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('weathers', function (Blueprint $table) {
$table->increments('id');
$table->string('name',10);
$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('weathers');
}
}
2 changes: 1 addition & 1 deletion resources/views/posts/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div class="category">
<h2>Category</h2>
<select name="post[category_id]">
<select name="post[weather_id]">
@foreach($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion resources/views/posts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h2 class='title'>
タイトル:<a href="/posts/{{ $post->id }}">{{ $post->title }}</a>
</h2>
<p class='body'>本文:{{ $post->body}}</p>
<p class='body'>本文:{{ $post->body }}</p>
<p>カテゴリー:<a href="/categories/{{ $post->category->id }}">{{ $post->category->name }}</a></p>
<form action="/posts/{{ $post->id }}" id="form_{{ $post->id }}" method="post" style="display:inline">
@csrf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<h1>レバテックチーム開発</h1>
<h2>カテゴリー「{{$posts->first()->category->name}}」の一覧ページ</h2>
<h2>カテゴリー「{{$posts->first()->category->}}」の一覧ページ</h2>
<div class='posts'>
@foreach($posts as $post)
<div class='post'>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;600&display=swap" rel="stylesheet">

//test
<!-- Styles -->
<style>
html, body {
Expand Down