Skip to content

Commit

Permalink
Change to Discussion and Channel repository
Browse files Browse the repository at this point in the history
  • Loading branch information
milanarandjelovic committed Apr 6, 2017
1 parent 4c0ea20 commit 919ed30
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions app/Http/Controllers/Forum/DiscussionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,59 @@

namespace App\Http\Controllers\Forum;

use App\Models\Channel;
use App\Models\Discussion;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\DiscussionRequest;
use App\LaraForum\Repositories\ChannelRepository;
use App\LaraForum\Repositories\DiscussionRepository;

class DiscussionController extends Controller
{

/**
* @var ChannelRepository
*/
private $channelRepository;

/**
* @var DiscussionRepository
*/
private $discussionRepository;

/**
* DiscussionController constructor.
*
* @param ChannelRepository $channelRepository
* @param DiscussionRepository $discussionRepository
*/
public function __construct(ChannelRepository $channelRepository, DiscussionRepository $discussionRepository)
{
$this->channelRepository = $channelRepository;
$this->discussionRepository = $discussionRepository;
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$channels = Channel::orderBy('name', 'asc')->with('discussions')->get();
$allDiscussions = Discussion::all()->count();
$channels = $this->channelRepository->getAllChannelsWithDiscussions();
$allDiscussions = $this->discussionRepository->all()->count();

return view('forum.discussion.index')
->with('allDiscussions', $allDiscussions)
->with('channels', $channels);
}

/**
* Show the form for creating a new resource.
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
$channels = Channel::orderBy('name', 'asc')->select('id', 'name')->get();
$channels = $this->channelRepository->all(['id', 'name']);

return view('forum.discussion.create')
->with('channels', $channels);
Expand All @@ -42,24 +63,18 @@ public function create()
/**
* Store a newly created resource in storage.
*
* @param DiscussionRequest|Request $request
* @return \Illuminate\Http\Response
* @param \App\Http\Requests\DiscussionRequest $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(DiscussionRequest $request)
{
$discussion = Discussion::create([
'title' => $request->input('title'),
'description' => $request->input('description'),
'channel_id' => $request->input('channel_id'),
'user_id' => $request->input('user_id'),
]);

$channel = Channel::where('id', $discussion->channel_id)->first();
$discussion = $this->discussionRepository->create($request->all());
$channel = $this->channelRepository->findBy('id', $discussion->channel_id);

activity()->by($request->input('user_id'))
->performedOn($channel)
->withProperties([
'type' => 'discussion',
'type' => 'discussion',
'title' => $discussion->title,
'link' => '/discuss/channels/' . $channel->channel_url . '/' . $discussion->slug,
])
Expand All @@ -77,11 +92,7 @@ public function store(DiscussionRequest $request)
*/
public function show($channelSlug, $slug)
{
$discussion = Discussion::where('slug', $slug)
->with('channel')
->with('user')
->with('comments')
->first();
$discussion = $this->discussionRepository->getDiscussionBySlug($slug);

return view('forum.channels.show')
->with('discussion', $discussion);
Expand Down

0 comments on commit 919ed30

Please sign in to comment.