mirror of
https://github.com/m1ngsama/php.git
synced 2025-12-24 07:56:01 +00:00
Build community and home page views
Added community listing, detail pages, and creation forms. Implemented home page with popular posts feed.
This commit is contained in:
parent
4efa2b09e3
commit
d0f10e0590
4 changed files with 249 additions and 0 deletions
39
resources/views/communities/create.blade.php
Normal file
39
resources/views/communities/create.blade.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
@extends('layout')
|
||||||
|
|
||||||
|
@section('title', 'Create Community')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-2xl mx-auto bg-white rounded-lg shadow p-8">
|
||||||
|
<h1 class="text-2xl font-bold mb-6">Create a Community</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('communities.store') }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="name" class="block text-gray-700 font-bold mb-2">Name</label>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="text-gray-700 mr-2">r/</span>
|
||||||
|
<input type="text" id="name" name="name" value="{{ old('name') }}" required
|
||||||
|
class="flex-1 px-3 py-2 border rounded focus:outline-none focus:border-orange-500">
|
||||||
|
</div>
|
||||||
|
<p class="text-sm text-gray-600 mt-1">Community names cannot be changed</p>
|
||||||
|
@error('name')
|
||||||
|
<p class="text-red-500 text-sm mt-1">{{ $message }}</p>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-6">
|
||||||
|
<label for="description" class="block text-gray-700 font-bold mb-2">Description</label>
|
||||||
|
<textarea id="description" name="description" rows="4"
|
||||||
|
class="w-full px-3 py-2 border rounded focus:outline-none focus:border-orange-500">{{ old('description') }}</textarea>
|
||||||
|
@error('description')
|
||||||
|
<p class="text-red-500 text-sm mt-1">{{ $message }}</p>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="bg-orange-600 text-white px-6 py-2 rounded hover:bg-orange-700 font-bold">
|
||||||
|
Create Community
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
35
resources/views/communities/index.blade.php
Normal file
35
resources/views/communities/index.blade.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
@extends('layout')
|
||||||
|
|
||||||
|
@section('title', 'Communities')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-4xl mx-auto">
|
||||||
|
<div class="flex justify-between items-center mb-6">
|
||||||
|
<h1 class="text-3xl font-bold">Communities</h1>
|
||||||
|
@auth
|
||||||
|
<a href="{{ route('communities.create') }}" class="bg-orange-600 text-white px-4 py-2 rounded hover:bg-orange-700">Create Community</a>
|
||||||
|
@endauth
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@forelse($communities as $community)
|
||||||
|
<div class="bg-white rounded-lg shadow mb-4 p-6">
|
||||||
|
<h2 class="text-2xl font-bold mb-2">
|
||||||
|
<a href="{{ route('communities.show', $community) }}" class="hover:text-orange-600">r/{{ $community->name }}</a>
|
||||||
|
</h2>
|
||||||
|
@if($community->description)
|
||||||
|
<p class="text-gray-700 mb-3">{{ $community->description }}</p>
|
||||||
|
@endif
|
||||||
|
<div class="text-sm text-gray-600">
|
||||||
|
{{ $community->posts_count }} posts • {{ $community->subscribers_count }} subscribers
|
||||||
|
• Created {{ $community->created_at->diffForHumans() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="text-gray-600">No communities yet. Be the first to create one!</p>
|
||||||
|
@endforelse
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
{{ $communities->links() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
94
resources/views/communities/show.blade.php
Normal file
94
resources/views/communities/show.blade.php
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
@extends('layout')
|
||||||
|
|
||||||
|
@section('title', 'r/' . $community->name)
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
|
<div class="lg:col-span-2">
|
||||||
|
<h1 class="text-3xl font-bold mb-6">r/{{ $community->name }}</h1>
|
||||||
|
|
||||||
|
@forelse($posts as $post)
|
||||||
|
<div class="bg-white rounded-lg shadow mb-4 p-4 flex">
|
||||||
|
<div class="flex flex-col items-center mr-4">
|
||||||
|
@auth
|
||||||
|
<form action="{{ route('posts.vote', $post) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="vote" value="1">
|
||||||
|
<button type="submit" class="text-gray-400 hover:text-orange-600">▲</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<span class="text-gray-400">▲</span>
|
||||||
|
@endauth
|
||||||
|
|
||||||
|
<span class="font-bold {{ $post->votes > 0 ? 'text-orange-600' : ($post->votes < 0 ? 'text-blue-600' : 'text-gray-600') }}">
|
||||||
|
{{ $post->votes }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
@auth
|
||||||
|
<form action="{{ route('posts.vote', $post) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="vote" value="-1">
|
||||||
|
<button type="submit" class="text-gray-400 hover:text-blue-600">▼</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<span class="text-gray-400">▼</span>
|
||||||
|
@endauth
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1">
|
||||||
|
<h2 class="text-xl font-semibold mb-2">
|
||||||
|
<a href="{{ route('posts.show', $post) }}" class="hover:text-orange-600">{{ $post->title }}</a>
|
||||||
|
</h2>
|
||||||
|
<div class="text-sm text-gray-600 mb-2">
|
||||||
|
Posted by <a href="{{ route('users.show', $post->user) }}" class="hover:underline">u/{{ $post->user->name }}</a>
|
||||||
|
• {{ $post->created_at->diffForHumans() }}
|
||||||
|
</div>
|
||||||
|
@if($post->content)
|
||||||
|
<p class="text-gray-700 mb-2">{{ Str::limit($post->content, 200) }}</p>
|
||||||
|
@endif
|
||||||
|
@if($post->url)
|
||||||
|
<a href="{{ $post->url }}" target="_blank" class="text-blue-600 hover:underline">{{ $post->url }}</a>
|
||||||
|
@endif
|
||||||
|
<div class="mt-2">
|
||||||
|
<a href="{{ route('posts.show', $post) }}" class="text-gray-600 hover:underline">
|
||||||
|
{{ $post->comments->count() }} comments
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="text-gray-600">No posts yet. Be the first to post!</p>
|
||||||
|
@endforelse
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
{{ $posts->links() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="lg:col-span-1">
|
||||||
|
<div class="bg-white rounded-lg shadow p-4">
|
||||||
|
<h2 class="text-xl font-bold mb-4">About r/{{ $community->name }}</h2>
|
||||||
|
@if($community->description)
|
||||||
|
<p class="text-gray-700 mb-4">{{ $community->description }}</p>
|
||||||
|
@endif
|
||||||
|
<div class="text-sm text-gray-600 mb-4">
|
||||||
|
Created by <a href="{{ route('users.show', $community->creator) }}" class="hover:underline">u/{{ $community->creator->name }}</a>
|
||||||
|
• {{ $community->created_at->diffForHumans() }}
|
||||||
|
</div>
|
||||||
|
@auth
|
||||||
|
@if(auth()->user()->subscribedCommunities->contains($community))
|
||||||
|
<form action="{{ route('communities.unsubscribe', $community) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<button type="submit" class="w-full bg-gray-200 text-gray-800 px-4 py-2 rounded hover:bg-gray-300">Unsubscribe</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<form action="{{ route('communities.subscribe', $community) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<button type="submit" class="w-full bg-orange-600 text-white px-4 py-2 rounded hover:bg-orange-700">Subscribe</button>
|
||||||
|
</form>
|
||||||
|
@endif
|
||||||
|
@endauth
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
81
resources/views/home.blade.php
Normal file
81
resources/views/home.blade.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
@extends('layout')
|
||||||
|
|
||||||
|
@section('title', 'Home')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||||
|
<div class="lg:col-span-2">
|
||||||
|
<h1 class="text-3xl font-bold mb-6">Popular Posts</h1>
|
||||||
|
|
||||||
|
@forelse($posts as $post)
|
||||||
|
<div class="bg-white rounded-lg shadow mb-4 p-4 flex">
|
||||||
|
<div class="flex flex-col items-center mr-4">
|
||||||
|
@auth
|
||||||
|
<form action="{{ route('posts.vote', $post) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="vote" value="1">
|
||||||
|
<button type="submit" class="text-gray-400 hover:text-orange-600">▲</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<span class="text-gray-400">▲</span>
|
||||||
|
@endauth
|
||||||
|
|
||||||
|
<span class="font-bold {{ $post->votes > 0 ? 'text-orange-600' : ($post->votes < 0 ? 'text-blue-600' : 'text-gray-600') }}">
|
||||||
|
{{ $post->votes }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
@auth
|
||||||
|
<form action="{{ route('posts.vote', $post) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="vote" value="-1">
|
||||||
|
<button type="submit" class="text-gray-400 hover:text-blue-600">▼</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<span class="text-gray-400">▼</span>
|
||||||
|
@endauth
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1">
|
||||||
|
<h2 class="text-xl font-semibold mb-2">
|
||||||
|
<a href="{{ route('posts.show', $post) }}" class="hover:text-orange-600">{{ $post->title }}</a>
|
||||||
|
</h2>
|
||||||
|
<div class="text-sm text-gray-600 mb-2">
|
||||||
|
<a href="{{ route('communities.show', $post->community) }}" class="font-bold hover:underline">r/{{ $post->community->name }}</a>
|
||||||
|
• Posted by <a href="{{ route('users.show', $post->user) }}" class="hover:underline">u/{{ $post->user->name }}</a>
|
||||||
|
• {{ $post->created_at->diffForHumans() }}
|
||||||
|
</div>
|
||||||
|
@if($post->content)
|
||||||
|
<p class="text-gray-700 mb-2">{{ Str::limit($post->content, 200) }}</p>
|
||||||
|
@endif
|
||||||
|
@if($post->url)
|
||||||
|
<a href="{{ $post->url }}" target="_blank" class="text-blue-600 hover:underline">{{ $post->url }}</a>
|
||||||
|
@endif
|
||||||
|
<div class="mt-2">
|
||||||
|
<a href="{{ route('posts.show', $post) }}" class="text-gray-600 hover:underline">
|
||||||
|
{{ $post->comments->count() }} comments
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="text-gray-600">No posts yet. Be the first to create one!</p>
|
||||||
|
@endforelse
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
{{ $posts->links() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="lg:col-span-1">
|
||||||
|
<div class="bg-white rounded-lg shadow p-4">
|
||||||
|
<h2 class="text-xl font-bold mb-4">About</h2>
|
||||||
|
<p class="text-gray-700 mb-4">Welcome to our Reddit-like community forum! Share your thoughts, engage in discussions, and connect with others.</p>
|
||||||
|
@auth
|
||||||
|
<a href="{{ route('posts.create') }}" class="block w-full text-center bg-orange-600 text-white px-4 py-2 rounded hover:bg-orange-700">Create Post</a>
|
||||||
|
@else
|
||||||
|
<a href="{{ route('register') }}" class="block w-full text-center bg-orange-600 text-white px-4 py-2 rounded hover:bg-orange-700">Sign Up</a>
|
||||||
|
@endauth
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
Loading…
Reference in a new issue