PostController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Post;
  5. use App\Models\Topic;
  6. use App\Models\Message;
  7. use App\Models\User;
  8. use Auth;
  9. use App\Models\SubtopicModerator;
  10. use App\Models\SubtopicSubscriber;
  11. class PostController extends Controller
  12. {
  13. public function showPost(string $sub,string $post_id){
  14. $post = Post::where('subwroteit',$sub)->where('post_id_string',$post_id)->first();
  15. return view('wroteit.show_post')->with(['posts' => $post]);
  16. }
  17. public function subscribe(string $sub){
  18. $userid=Auth::user()->id;
  19. $rel = array('subtopic' => $sub, 'subscriber_id' => $userid);
  20. SubtopicSubscriber::create($rel);
  21. return redirect()->route('show_topic',['sub' => $sub]);
  22. }
  23. public function showTopics(){
  24. $topics = Topic::orderby('updated_at','desc')->get();
  25. return view('wroteit.list_topics')->with(['topics' => $topics]);
  26. }
  27. public function showSubscriptions(){
  28. $subbed = SubtopicSubscriber::select('subtopic')->where('subscriber_id',Auth::user()->id);
  29. $topics = Topic::orderby('updated_at','desc')->whereIn('title',$subbed)->paginate(6);
  30. return view('wroteit.list_topics')->with(['topics' => $topics]);
  31. }
  32. }