|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
use App\Models\Post;
|
|
use App\Models\Post;
|
|
|
|
+use App\Models\Comment;
|
|
use App\Models\Topic;
|
|
use App\Models\Topic;
|
|
use App\Models\Message;
|
|
use App\Models\Message;
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
@@ -17,8 +18,9 @@ use App\Http\Requests\NewPostRequest;
|
|
class PostController extends Controller
|
|
class PostController extends Controller
|
|
{
|
|
{
|
|
public function showPost(string $sub,string $post_id){
|
|
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){
|
|
public function subscribe(string $sub){
|
|
$userid=Auth::user()->id;
|
|
$userid=Auth::user()->id;
|
|
@@ -39,6 +41,7 @@ class PostController extends Controller
|
|
$topics = Topic::orderby('updated_at','desc')->get();
|
|
$topics = Topic::orderby('updated_at','desc')->get();
|
|
return view('wroteit.list_topics')->with(['topics' => $topics]);
|
|
return view('wroteit.list_topics')->with(['topics' => $topics]);
|
|
}
|
|
}
|
|
|
|
+
|
|
public function showSubscriptions(){
|
|
public function showSubscriptions(){
|
|
$subbed = SubtopicSubscriber::select('subtopic')->where('subscriber_id',Auth::user()->id);
|
|
$subbed = SubtopicSubscriber::select('subtopic')->where('subscriber_id',Auth::user()->id);
|
|
$topics = Topic::orderby('updated_at','desc')->whereIn('title',$subbed)->paginate(6);
|
|
$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->content = $request->input('content');
|
|
$post->by_user = Auth::user()->name;
|
|
$post->by_user = Auth::user()->name;
|
|
$post->subwroteit = $request->input('sub');
|
|
$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->score = 0;
|
|
$post->number_comments = 0;
|
|
$post->number_comments = 0;
|
|
$post->save();
|
|
$post->save();
|
|
//$this->store_relation_subtopicSubscriber($subtopic_name, $user_id);
|
|
//$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;
|
|
|
|
+ }
|
|
}
|
|
}
|