hootlex / laravel-moderation

A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.
MIT License
527 stars 68 forks source link

Requesting Help #18

Closed HDVinnie closed 7 years ago

HDVinnie commented 7 years ago

I have a question that has nothing to do with a issue of package but instead just my noobness needing some help.

Heres my view: (displays all torrents pending)

@extends('layout.default') 

@section('title')
<title>Torrents - {{ Config::get('other.title') }}</title>
@stop 

@section('breadcrumb')
<li class="active">
  <a href="{!! route('moderation') !!}" itemprop="url" class="l-breadcrumb-item-link">
    <span itemprop="title" class="l-breadcrumb-item-link-title">Moderation</span>
  </a>
</li>
@stop 

@section('content')
<div class="container box">
  <div class="torrents col-md-12">
    <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th>Category</th>
          <th>Name</th>
          <th>Type</th>
          <th>Size</th>
          <th>Uploader</th>
          <th>Approve</th>
          <th>Reject</th>
          <th>Postpone</th>
        </tr>
      </thead>
      <tbody>
        @foreach($pending as $p)
        <tr>
        <td>{{ $p->category->name }}</td>
        <td>{{ $p->name }}</td>
        <td>{{ $p->type }}</td>
        <td>{{ $p->getSize() }}</td>
        <td>{{ $p->user->username }}</td>
        <td><button class="btn btn-labeled btn-success" type="button"><span class="btn-label"><i class="fa fa-thumbs-up"></i></span>Approve</button></td>
        <td><button class="btn btn-labeled btn-danger" type="button"><span class="btn-label"><i class="fa fa-thumbs-down"></i></span>Reject</button></td>
        <td><button class="btn btn-labeled btn-warning" type="button"><span class="btn-label"><i class="fa fa-stop"></i></span>Postpone</button></td>
        </tr>
        @endforeach
      </tbody>
    </table>
  </div>
</div>
@stop

Heres part of my controller that does this:

        /**
    * Torrent Moderation
    *
    * @access public
    * @param $slug Slug of the torrent
    * @param $id Id of the torrent
    *
    */
    public function moderation()
    {
        $approve = Torrent::where('name', '=', Request::get('name'))->approve();
        $pending = Torrent::pending()->get(); //returns all Pending Torrents
        return view('torrent.moderation', ['pending' => $pending, 'approve' => $approve]);
    }

Heres a pic of the view: http://i.imgur.com/6B3i06u.png?1

Question Is: How can I make it so my Approve Button when clicked approves the torrent in question. I added this to controller $approve = Torrent::where('name', '=', Request::get('name'))->approve(); but don't know how to apply it to a button.

hootlex commented 7 years ago

When you hit a button you should make a AJAX call or redirect the user to a route which will run the approve method.

I am closing this issue since it is project-specific.