3 Комити 03d90ce682 ... fbe3ef337a

Аутор SHA1 Порука Датум
  socket_ fbe3ef337a minor changes пре 3 година
  socket_ f5a454ca86 Merged with develop пре 3 година
  socket_ 78ffac33b8 started working on showing a post пре 3 година

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

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use App\Models\Post;
+use App\Models\Message;
+use App\Models\User;
+use Auth;
+
+class PostController extends Controller
+{
+	public function showPost(string $sub,string $post_id){
+		$posts = Post::where('subwroteit',$sub)->where('post_id_string',$post_id)->get();
+        return view('wroteit.show_post')->with(['posts' => $posts]);
+	}
+}

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

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 use App\Models\Topic;
+use App\Models\Post;
 use App\Models\Message;
 use App\Models\User;
 use Auth;
@@ -13,8 +14,8 @@ class WroteitController extends Controller
     // Views call and stuff
 
     public function main(){
-        $topics = Topic::orderby('updated_at','desc')->paginate(6);
-        return view('wroteit.main')->with(['topics' => $topics]);
+        $posts = Post::orderby('updated_at','desc')->paginate(6);
+        return view('wroteit.main')->with(['topics' => $posts]);//changed to use posts instead of topics, but more changes needed
     }
 
     public function show_topic(Topic $top){

+ 11 - 0
app/Models/Post.php

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

+ 2 - 2
database/migrations/2021_05_06_220510_create_topic_table.php

@@ -13,7 +13,7 @@ class CreateTopicTable extends Migration
      */
     public function up()
     {
-        Schema::create('Topic', function (Blueprint $table) {
+        Schema::create('topic', function (Blueprint $table) {
             $table->id();
             $table->string('title');
             $table->string('description');
@@ -30,6 +30,6 @@ class CreateTopicTable extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('Topic');
+        Schema::dropIfExists('topic');
     }
 }

+ 12 - 8
database/migrations/2021_05_07_094600_create_message_table.php

@@ -13,19 +13,23 @@ class CreateMessageTable extends Migration
      */
     public function up()
     {
-        Schema::create('Message', function (Blueprint $table) {
+        Schema::create('messages', function (Blueprint $table) {
             $table->id();
             $table->string('title');
             $table->text('body');
-            $table->integer('from_id')->unsigned();
-            $table->integer('to_id')->unsigned();
+			/*
+             *$table->integer('from_id')->unsigned();
+             *$table->integer('to_id')->unsigned();
+			 */
+			$table->foreignId('from_id')->unique()->constrained('users')->onDelete('cascade');
+			$table->foreignId('to_id')->unique()->constrained('users')->onDelete('cascade');
             $table->timestamps();
         });
 
-        Schema::table('Message', function(Blueprint $table){
-            $table->foreign('from_id')->references('id')->on('users')->onDelete('cascade');
-            $table->foreign('to_id')->references('id')->on('users')->onDelete('cascade');
-        });
+		/*
+         *Schema::table('messages', function(Blueprint $table){
+         *});
+		 */
     }
 
     /**
@@ -35,6 +39,6 @@ class CreateMessageTable extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('Message');
+        Schema::dropIfExists('messages');
     }
 }

+ 38 - 0
database/migrations/2021_05_07_200909_create_posts_table.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreatePostsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('posts', function (Blueprint $table) {
+            $table->id();
+            $table->timestamps();
+			$table->string('title');
+			$table->string('content');
+			$table->string('by_user');
+			$table->string('subwroteit');
+			$table->string('post_id_string')->unique();
+			$table->string('score');
+			$table->string('number_comments');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('posts');
+    }
+}

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

@@ -1,4 +1,5 @@
 @extends('layouts.header')
+
 @section('content')
     @foreach($topics as $topic)
         <h2><a href="{{ route('show_topic',['top'=>$topic->id]) }} " title="Show topic">{{$topic->title}}</a> by {{$topic->author}}</h2>
@@ -6,4 +7,4 @@
         <hr/>
         <br />
     @endforeach
-@endsection()
+@endsection()

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

@@ -0,0 +1,10 @@
+@extends('layouts.header')
+@section('content')
+
+    @foreach($posts as $post)
+        <h2>{{ $post->title }} by {{$post->author}}</h2>
+		<h3>{{ $post->content }} </h3>
+        <hr/>
+        <br />
+    @endforeach
+@endsection()

+ 2 - 0
routes/web.php

@@ -26,6 +26,8 @@ Route::get('/wroteit/{top}','App\Http\Controllers\WroteitController@show_topic')
 
 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::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
     return view('dashboard');
 })->name('dashboard');