2 کامیت‌ها fb31115cd0 ... efa235dea1

نویسنده SHA1 پیام تاریخ
  socket_ efa235dea1 merged with Michal's CSS header 3 سال پیش
  socket_ 8f5a1ff5f1 Fixed so main shows posts and separate views to show topics 3 سال پیش

+ 1 - 1
app/Actions/Fortify/CreateNewUser.php

@@ -23,7 +23,7 @@ class CreateNewUser implements CreatesNewUsers
     public function create(array $input)
     {
         Validator::make($input, [
-            'name' => ['required', 'string', 'max:255'],
+            'name' => ['required', 'string', 'max:255', 'unique:users'],
             'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
             'password' => $this->passwordRules(),
             'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',

+ 11 - 0
app/Http/Controllers/PostController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use Illuminate\Http\Request;
 
 use App\Models\Post;
+use App\Models\Topic;
 use App\Models\Message;
 use App\Models\User;
 use Auth;
@@ -24,4 +25,14 @@ class PostController extends Controller
         SubtopicSubscriber::create($rel);
         return redirect()->route('show_topic',['sub' => $sub]);
 	}
+
+	public function showTopics(){
+		$topics = Topic::orderby('updated_at','desc')->get();
+        return view('wroteit.list_topics')->with(['topics' => $topics]);
+	}
+	public function showSubscriptions(){
+		$subbed = SubtopicSubscriber::select('subtopic')->where('subscriber_id',Auth::user()->id);
+    	$topics = Topic::orderby('updated_at','desc')->whereIn('title',$subbed)->paginate(6);
+        return view('wroteit.list_topics')->with(['topics' => $topics]);
+	}
 }

+ 3 - 2
app/Http/Controllers/WroteitController.php

@@ -20,10 +20,11 @@ class WroteitController extends Controller
 
     public function main(){
 		if(Auth::check()){
-			$posts = Post::orderby('updated_at','desc');
+			$subbed = SubtopicSubscriber::select('subtopic')->where('subscriber_id',Auth::user()->id);
+        	$posts = Post::orderby('updated_at','desc')->whereIn('subwroteit',$subbed)->get();
 		}
 		else{
-        	$posts = Post::orderby('updated_at','desc')->paginate(6);
+			$posts = Post::orderby('updated_at','desc')->get();
 		}
         return view('wroteit.main')->with(['posts' => $posts]);
     }

+ 1 - 1
database/migrations/2014_10_12_000000_create_users_table.php

@@ -15,7 +15,7 @@ class CreateUsersTable extends Migration
     {
         Schema::create('users', function (Blueprint $table) {
             $table->id();
-            $table->string('name');
+            $table->string('name')->unique();
             $table->string('email')->unique();
             $table->timestamp('email_verified_at')->nullable();
             $table->string('password');

+ 11 - 7
resources/views/layouts/header.blade.php

@@ -1,23 +1,27 @@
 <!DOCTYPE html>
 <html lang="{{ str_replace('_','-', app()->getLocale()) }}">
     <head>
-        <meta charset="UTF-8">       
-        <title>Wroteit</title>        
+        <meta charset="UTF-8">
+        <title>Wroteit</title>
     </head>
-    <body style="background-image: linear-gradient(to bottom right, #f7f3ee, #f7f1e6);">     
-        <h1 style="text-align: center;"><img src="{{ asset('/img/logo.png') }}" style="width:32px;height:32px;">  Wroteit</h1>        
+    <body style="background-image: linear-gradient(to bottom right, #f7f3ee, #f7f1e6);">
+        <h1 style="text-align: center;"><img src="{{ asset('/img/logo.png') }}" style="width:32px;height:32px;">  Wroteit</h1>
         @if (Auth::check())
             <h3 style="position:absolute;left:1%;top:5%">Welcome back, {{Auth::user()->name}} <a href=" {{route('logout')}}" title="Logout">Logout</a></h3>
-            <h4 style="position:absolute;right:1%;top:5%"><a href=" {{route('messages_main')}}" title="Messages">Check messages</a></h4>
+			<h4 style="position:absolute;right:1%;top:5%">
+				<a href=" {{route('messages_main')}}" title="Messages">Check messages</a>
+				<a href="{{ route('list_subscriptions') }}" title="Subscriptions">My subscriptions</a>
+				<a href="{{ route('list_all_topics') }}" title="Topics">List topics</a>
+			</h4>
         @else
             <p><h3 style="text-align:center;">Welcome wroter. Do you have an account? <a href=" {{route('login')}}" title="Login">Login</a> Or do you need a new one? <a href=" {{route('register')}}" title="Register">Register</a></h3></p>
         @endif
 
         @if (Route::currentRouteName() != 'main')
-            <h4 style="position:absolute;right:10%;top:5%"><a href=" {{route('main')}}" title="Go main">Go to main page</a></h4>
+            <h4 style="position:absolute;left:3%;top:1%"><a href=" {{route('main')}}" title="Go main">Go to main page</a></h4>
         @endif
         <hr>
 
         @yield('content')
     </body>
-</html>
+</html>

+ 11 - 0
resources/views/wroteit/list_topics.blade.php

@@ -0,0 +1,11 @@
+@extends('layouts.header')
+@section('content')
+@if (Auth::check()) {{-- Only logged users can create subtopics, obv --}}
+    <h3><a href="{{ route('new_subtopic') }} " title="Create subtopic">Create new subtopic</a></h3>
+@endif
+	@foreach($topics as $topic)
+		<h2><a href="{{ route('show_topic',['sub'=>$topic->title]) }} " title="Show topic">{{$topic->title}}</a></h2>
+        <h5>posts_number({{$topic->posts_number}}) / created in: {{$topic->created_at}} / last update: {{$topic->updated_at}} </h5>
+		<br><br>
+	@endforeach
+@endsection()

+ 2 - 6
resources/views/wroteit/main.blade.php

@@ -1,10 +1,5 @@
 @extends('layouts.header')
 @section('content')
-@if (Auth::check()) {{-- Only logged users can create subtopics, obv --}}
-    <ul>
-        <li><h3><a href="{{ route('new_subtopic') }} " title="Create subtopic">Create new subtopic</a></h3></li>
-    </ul>    
-@endif
      {{--@foreach($topics as $topic)
         <h2><a href="{{ route('show_topic',['top'=>$topic->id]) }} " title="Show topic">{{$topic->title}}</a></h2>
         <h5>posts_number({{$topic->posts_number}}) / created in: {{$topic->created_at}} / last update: {{$topic->updated_at}} </h5>
@@ -12,6 +7,7 @@
         <br />
     @endforeach--}}
 	@foreach($posts as $post)
-		
+		<h2><a href="{{ route('show_post',['sub'=>$post->subwroteit],['post_id' => $post->post_id_string]) }} " title="Show post">{{$post->title}}</a></h2>
+		<br><br>
 	@endforeach
 @endsection()

+ 2 - 1
routes/web.php

@@ -34,7 +34,8 @@ Route::get('logout','App\Http\Controllers\LoginController@logout')->name('logout
 Route::get('/w/{sub}/{post_id}','App\Http\Controllers\PostController@showPost')->name('show_post');
 Route::get('/w/{sub}','App\Http\Controllers\WroteitController@show_topic')->name('show_topic');
 Route::get('/subscribe/{sub}','App\Http\Controllers\PostController@subscribe')->name('subscribe');
-
+Route::get('/list/subscriptions','App\Http\Controllers\PostController@showSubscriptions')->name('list_subscriptions');
+Route::get('/list/all_topics','App\Http\Controllers\PostController@showTopics')->name('list_all_topics');
 
 
 Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {