3 Коммиты b1a9ce738d ... 394afcee6f

Автор SHA1 Сообщение Дата
  socket_ 394afcee6f Merge branch 'master' of notabug.org:webProgrammingPeople/wroteit 3 лет назад
  socket_ bb32816e57 merging 3 лет назад
  socket_ 3b9f5d6a78 merge nightmare time 3 лет назад

+ 23 - 4
app/Http/Controllers/PostController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use Illuminate\Http\Request;
 
 use App\Models\Post;
+use App\Models\Comment;
 use App\Models\Topic;
 use App\Models\Message;
 use App\Models\User;
@@ -17,8 +18,9 @@ use App\Http\Requests\NewPostRequest;
 class PostController extends Controller
 {
 	public function showPost(string $sub,string $post_id){
-		$post = Post::where('subwroteit','=',$sub)->where('post_id_string','=',$post_id)->first();
-        return view('wroteit.show_post')->with(['post' => $post]);
+		$post = Post::where('subwroteit',$sub)->where('post_id_string',$post_id)->first();
+		$comments = Comment::where('subwroteitID',$sub)->where('postID',$post_id)->orderby('updated_at','desc')->paginate(10);
+        return view('wroteit.show_post')->with(['post' => $post])->with(['comments' => $comments]);
 	}
 	public function subscribe(string $sub){
 		$userid=Auth::user()->id;
@@ -39,6 +41,7 @@ class PostController extends Controller
 		$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);
@@ -53,12 +56,28 @@ class PostController extends Controller
 		$post->content = $request->input('content');
         $post->by_user = Auth::user()->name;
 		$post->subwroteit = $request->input('sub');
-		$post->post_id_string = "kel";
+		$post->post_id_string = $this->generateFancyPostID($request->input('sub'),$request->input('title'));
 		$post->score = 0;
 		$post->number_comments = 0;
 		$post->save();
         //$this->store_relation_subtopicSubscriber($subtopic_name, $user_id);
-        return redirect()->route('show_post')->with(['sub' => $request->input('sub')])->with(['post_id' => $post->post_id_string]);
+        //return redirect()->route('show_post',['sub' => $request->input('sub')],['post_id' => $post->post_id_string]);
+		return redirect()->route('main');
     }
+	//public function storeNewComment(New)
 
+	public static function generateFancyPostID(string $sub,string $title){
+		$vanilla=$title;
+		$number=0;
+		$foundFancy=false;
+		while(!$foundFancy){
+			$number++;
+			$fancy=$title . $number;
+			$post = Post::where('subwroteit',$sub)->where('post_id_string',$fancy)->first();
+			if(is_null($post)){
+				$foundFancy=true;
+			}
+		}
+		return $fancy;
+	}
 }

+ 1 - 0
app/Http/Controllers/WroteitController.php

@@ -26,6 +26,7 @@ class WroteitController extends Controller
 		else{
 			$posts = Post::orderby('updated_at','desc')->get();
 		}
+			$posts = Post::orderby('updated_at','desc')->get();
         return view('wroteit.main')->with(['posts' => $posts]);
     }
 

+ 30 - 0
app/Http/Requests/NewCommentRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class NewCommentRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 11 - 0
app/Models/Comment.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Comment extends Model
+{
+    use HasFactory;
+}

+ 1 - 1
database/migrations/2021_05_07_200909_create_posts_table.php

@@ -20,7 +20,7 @@ class CreatePostsTable extends Migration
 			$table->string('content');
 			$table->string('by_user');
 			$table->string('subwroteit');
-			$table->string('post_id_string')->unique();
+			$table->string('post_id_string');
 			$table->string('score');
 			$table->string('number_comments');
         });

+ 35 - 0
database/migrations/2021_05_10_224135_create_comments_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCommentsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('comments', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+			$table->string('userName');
+			$table->string('subwroteitID');
+			$table->string('postID');
+			$table->string('content');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('comments');
+    }
+}

+ 25 - 0
resources/views/wroteit/show_post.blade.php

@@ -4,4 +4,29 @@
 	<h3>{{ $post->content }} </h3>
 	<hr/>
 	<br />
+
+    <form action="{{ route('store_new_comment') }}" method="POST" style="text-align: center;">
+        {{ csrf_field() }}
+
+        <div class="form-group">
+            <label for="content">Content: </label><textarea rows="8" style="width: 1218px;" name="content" class="input" >{{ old('content')}}</textarea> <br /><br />
+        </div>
+        <div class="form-group">
+            <input type="hidden" name="sub" value="{{ $sub }}">
+            <input type="hidden" name="postID" value="{{ $post->post_id_string }}">
+            <button type="submit" class='btn btn-primary'>Publish</button>
+        </div>
+
+    </form>
+
+
+
+
+
+	@foreach($comments as $comment)
+		<h3>{{ $comment->content }}<h5>by {{ $comment->userName }}</h5><h3>
+	@endforeach
+	{{ $comments->links() }}
+
+
 @endsection()

+ 1 - 1
routes/web.php

@@ -40,7 +40,7 @@ Route::get('/list/all_topics','App\Http\Controllers\PostController@showTopics')-
 
 //new post stuff
 Route::get('/newpost/{sub}','App\Http\Controllers\PostController@newPost')->name('new_post');
-Route::post('/wroteit','App\Http\Controllers\PostController@storeNewPost')->name('store_new_post');
+Route::post('/save_post','App\Http\Controllers\PostController@storeNewPost')->name('store_new_post');
 
 Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
     return view('dashboard');