59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\TopicRequest;
|
|
use App\Models\Topic;
|
|
use Illuminate\Http\Request;
|
|
|
|
class TopicsController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth', ['except' => ['index', 'show']]);
|
|
}
|
|
|
|
public function index(Request $request, Topic $topic)
|
|
{
|
|
$topics = $topic->with('user', 'category')->withOrder($request->order)->paginate();
|
|
return view('topics.index', compact('topics'));
|
|
}
|
|
|
|
public function show(Topic $topic)
|
|
{
|
|
return view('topics.show', compact('topic'));
|
|
}
|
|
|
|
public function create(Topic $topic)
|
|
{
|
|
return view('topics.create_and_edit', compact('topic'));
|
|
}
|
|
|
|
public function store(TopicRequest $request)
|
|
{
|
|
$topic = Topic::create($request->all());
|
|
return redirect()->route('topics.show', $topic->id)->with('message', 'Created successfully.');
|
|
}
|
|
|
|
public function edit(Topic $topic)
|
|
{
|
|
$this->authorize('update', $topic);
|
|
return view('topics.create_and_edit', compact('topic'));
|
|
}
|
|
|
|
public function update(TopicRequest $request, Topic $topic)
|
|
{
|
|
$this->authorize('update', $topic);
|
|
$topic->update($request->all());
|
|
|
|
return redirect()->route('topics.show', $topic->id)->with('message', 'Updated successfully.');
|
|
}
|
|
|
|
public function destroy(Topic $topic)
|
|
{
|
|
$this->authorize('destroy', $topic);
|
|
$topic->delete();
|
|
|
|
return redirect()->route('topics.index')->with('message', 'Deleted successfully.');
|
|
}
|
|
} |