You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.4 KiB
PHTML

6 years ago
<?php
namespace App\Http\Controllers;
use App\Thread;
6 years ago
use App\Http\Resources\ThreadsCollection;
6 years ago
use Illuminate\Http\Request;
6 years ago
use Illuminate\Support\Collection;
6 years ago
class ThreadController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
6 years ago
return new ThreadsCollection(Thread::with("creator")->get()->sortByDesc('created_at'));
6 years ago
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view("create_thread");
6 years ago
}
/**
* Show thread view.
*
* @param int $thread
*/
public function view_thread(int $thread_id) {
return view("thread")->with("thread_id", $thread_id);
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function edit(Thread $thread)
{
return view("edit")->withThread($thread);
}
6 years ago
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$thread = new Thread;
//dd($request);
$thread->thread_title = $request->thread_title;
$thread->thread_creator_id = $request->user_id;
$thread->save();
6 years ago
}
/**
* Display the specified resource.
*
* @param integer $id
* - A thread ID
6 years ago
* @return \Illuminate\Http\Response
*/
public function show(int $id)
6 years ago
{
$selected_thread = new ThreadsCollection(Thread::with("creator")->get()->where("id", $id));
//dd(Thread::with("posts")->get()->where("id", $id));
return Thread::with("creator")->find($id);//$selected_thread;
6 years ago
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Thread $thread)
{
$thread->thread_title = $request->thread_title;
$thread->save();
6 years ago
}
/**
* Remove the specified resource from storage.
*
* @param int $int
6 years ago
* @return \Illuminate\Http\Response
*/
public function destroy(int $id)
6 years ago
{
Thread::find($id)->delete();
6 years ago
}
}