Skip to content

Commit

Permalink
投稿画面作成
Browse files Browse the repository at this point in the history
  • Loading branch information
maibaba committed Nov 10, 2022
1 parent 2b361a8 commit e3204e9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 52 deletions.
8 changes: 8 additions & 0 deletions src/resources/views/components/alert/error.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div
class="w-full mt-1 mb-2 p-2 bg-red-500 items-center text-white leading-none lg:rounded-full flex lg:inline-flex"
role="alert">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
<span class="font-semibold mr-2 text-left flex-auto pl-1">{{ $slot }}</span>
</div>
6 changes: 6 additions & 0 deletions src/resources/views/components/element/button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<button
type="submit"
class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-500 hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
>
{{ $slot }}
</button>
16 changes: 16 additions & 0 deletions src/resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="{{ mix('/css/app.css') }}" rel="stylesheet">
<script src="{{ mix('js/app.js') }}"></script>
<title>{{ $title ?? 'つぶやきアプリ' }}</title>

</head>
<body class="bg-gray-50">
{{ $slot }}
</body>
</html>
27 changes: 27 additions & 0 deletions src/resources/views/components/tweet/form/post.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@auth
<div class="p-4">
<form action="{{ route('tweet.create') }}" method="post">
@csrf
<div class="mt-1">
<textarea
name="tweet"
rows="3"
class="focus:ring-blue-400 focus:border-blue-400 mt-1 block w-full sm:text-sm border border-gray-300 rounded-md p-2"
placeholder="つぶやきを入力"></textarea>
</div>
<p class="mt-2 text-sm text-gray-500">
140文字まで
</p>

@error('tweet')
<x-alert.error>{{ $message }}</x-alert.error>
@enderror

<div class="flex flex-wrap justify-end">
<x-element.button>
つぶやく
</x-element.button>
</div>
</form>
</div>
@endauth
60 changes: 8 additions & 52 deletions src/resources/views/tweet/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,8 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>つぶやきアプリ</title>
</head>
<body>
<h1>つぶやきアプリ</h1>
@auth
<div>
<p>投稿フォーム</p>
@if (session('feedback.success'))
<p style="color: green">{{ session('feedback.success') }}</p>
@endif
<form action="{{ route('tweet.create') }}" method="post">
@csrf
<label for="tweet-content">つぶやき</label>
<span>140文字まで</span>
<textarea id="tweet-content" type="text" name="tweet" placeholder="つぶやきを入力"></textarea>
@error('tweet')
<p style="color: red;">{{ $message }}</p>
@enderror
<button type="submit">投稿</button>
</form>
</div>
@endauth
<div>
@foreach($tweets as $tweet)
<details>
<summary>
{{ $tweet->content }} by {{ $tweet->user->name }}
</summary>
@if(Illuminate\Support\Facades\Auth::id() === $tweet->user_id)
<div>
<a href="{{ route('tweet.update.index', $tweet->id) }}">編集</a>
<form action="{{ route('tweet.delete', $tweet->id) }}" method="post">
@method('DELETE')
@csrf
<button type="submit">削除</button>
</form>
</div>
@else
編集できません
@endif
</details>
@endforeach
</div>
</body>
</html>
<x-layout title="TOP | つぶやきアプリ">
<x-layout.single>
<h2 class="text-center text-blue-500 text-4xl font-bold mt-8 mb-8">
つぶやきアプリ
</h2>
<x-tweet.form.post></x-tweet.form.post>
</x-layout.single>
</x-layout>

0 comments on commit e3204e9

Please sign in to comment.