Skip to content

Commit

Permalink
詳細画面と一覧画面を作成
Browse files Browse the repository at this point in the history
  • Loading branch information
ryotamedx committed Sep 18, 2021
1 parent 8321c90 commit 9318092
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Item;

class ItemController extends Controller
{
public function index()
{
$items = Item::all();
return view('items.index', ['items' => $items]);
}

public function show($id)
{
$item = Item::find($id);
return view('items.show', ['item' => $item]);
}
}
19 changes: 19 additions & 0 deletions resources/views/items/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>出品商品一覧</h1>
<ul>
@foreach ($items as $item)
<a href="/items/{{ $item->id }}">
<li>{{ $item->name }}</li>
</a>
@endforeach
</ul>
</body>
</html>
29 changes: 29 additions & 0 deletions resources/views/items/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p>
<b>商品名:{{ $item->name }}</b>
</p>
<p>
<b>商品詳細:{{ $item->description }}</b>
</p>
<p>
<b>価格:{{ $item->price }}</b>
</p>
<p>
<b>出品者:{{ $item->seller }}</b>
</p>
<p>
<b>電子メール:{{ $item->email }}</b>
</p>
<p>
<img src="{{ $item->image_url }}" alt="">
</p>
</body>
</html>
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
Route::get('/', function () {
return view('welcome');
});

Route::resource('items', App\Http\Controllers\ItemController::class);
2 changes: 2 additions & 0 deletions storage/debugbar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 9318092

Please sign in to comment.