PHP code example of laravelplus / feature-requests

1. Go to this page and download the library: Download laravelplus/feature-requests library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravelplus / feature-requests example snippets


return [
    'middleware' => ['web', 'auth'],
    'prefix' => 'feature-requests',
    'user' => [
        'model' => App\Models\User::class,
    ],
    'default_categories' => [
        'User Interface',
        'Performance',
        'Security',
        'API',
        'Mobile',
        'Integration',
    ],
];

use LaravelPlus\FeatureRequests\Models\FeatureRequest;

$featureRequest = FeatureRequest::create([
    'title' => 'Dark Mode Support',
    'description' => 'Add dark mode theme to the application',
    'category_id' => 1,
    'priority' => 'medium',
    'user_id' => auth()->id(),
    'is_public' => true,
]);

use LaravelPlus\FeatureRequests\Models\Vote;

$vote = Vote::create([
    'user_id' => auth()->id(),
    'feature_request_id' => $featureRequest->id,
    'vote_type' => 'up',
]);

use LaravelPlus\FeatureRequests\Models\Comment;

$comment = Comment::create([
    'user_id' => auth()->id(),
    'feature_request_id' => $featureRequest->id,
    'content' => 'This would be a great addition!',
]);

// Feature Requests
GET    /feature-requests              // Index
GET    /feature-requests/create       // Create form
POST   /feature-requests              // Store
GET    /feature-requests/{slug}       // Show
GET    /feature-requests/{slug}/edit  // Edit form
PUT    /feature-requests/{slug}       // Update
DELETE /feature-requests/{slug}       // Destroy

// Voting
POST   /feature-requests/{slug}/vote  // Vote
DELETE /feature-requests/{slug}/vote  // Unvote

// Comments
POST   /feature-requests/{slug}/comments  // Store comment
PUT    /feature-requests/comments/{comment}  // Update comment
DELETE /feature-requests/comments/{comment}  // Delete comment

// Categories
GET    /feature-requests/categories              // Index
GET    /feature-requests/categories/create       // Create form
POST   /feature-requests/categories              // Store
GET    /feature-requests/categories/{slug}       // Show
GET    /feature-requests/categories/{slug}/edit  // Edit form
PUT    /feature-requests/categories/{slug}       // Update
DELETE /feature-requests/categories/{slug}       // Destroy

// Feature Requests API
GET    /api/feature-requests                    // List all
POST   /api/feature-requests                    // Create
GET    /api/feature-requests/{slug}             // Show
PUT    /api/feature-requests/{slug}             // Update
DELETE /api/feature-requests/{slug}             // Delete
PATCH  /api/feature-requests/{slug}/status      // Update status
PATCH  /api/feature-requests/{slug}/assign      // Assign to user
PATCH  /api/feature-requests/{slug}/toggle-featured // Toggle featured

// Voting API
POST   /api/feature-requests/{slug}/vote        // Vote
DELETE /api/feature-requests/{slug}/vote        // Unvote
GET    /api/feature-requests/votes/statistics   // Vote statistics

// Comments API
GET    /api/feature-requests/comments           // List comments
POST   /api/feature-requests/comments           // Create comment
PUT    /api/feature-requests/comments/{id}      // Update comment
DELETE /api/feature-requests/comments/{id}      // Delete comment

// Categories API
GET    /api/feature-requests/categories         // List categories
POST   /api/feature-requests/categories         // Create category
PUT    /api/feature-requests/categories/{slug}  // Update category
DELETE /api/feature-requests/categories/{slug}  // Delete category

use LaravelPlus\FeatureRequests\Models\FeatureRequest;

// Scopes
$featureRequests = FeatureRequest::published()->get();
$featureRequests = FeatureRequest::featured()->get();
$featureRequests = FeatureRequest::byStatus('pending')->get();
$featureRequests = FeatureRequest::byPriority('high')->get();
$featureRequests = FeatureRequest::byCategory($categoryId)->get();
$featureRequests = FeatureRequest::mostVoted()->get();
$featureRequests = FeatureRequest::recent()->get();

// Relationships
$featureRequest->user;           // BelongsTo User
$featureRequest->category;       // BelongsTo Category
$featureRequest->votes;          // HasMany Vote
$featureRequest->comments;       // HasMany Comment

use LaravelPlus\FeatureRequests\Models\Category;

// Scopes
$categories = Category::active()->get();
$categories = Category::bySlug('user-interface')->get();
$categories = Category::withFeatureRequests()->get();

// Relationships
$category->featureRequests;      // HasMany FeatureRequest

use LaravelPlus\FeatureRequests\Models\Vote;

// Scopes
$votes = Vote::byType('up')->get();
$votes = Vote::byUser($userId)->get();
$votes = Vote::byFeatureRequest($featureRequestId)->get();
$votes = Vote::upVotes()->get();
$votes = Vote::downVotes()->get();

// Relationships
$vote->user;                     // BelongsTo User
$vote->featureRequest;           // BelongsTo FeatureRequest

use LaravelPlus\FeatureRequests\Models\Comment;

// Scopes
$comments = Comment::approved()->get();
$comments = Comment::pinned()->get();
$comments = Comment::byUser($userId)->get();
$comments = Comment::byFeatureRequest($featureRequestId)->get();
$comments = Comment::parentComments()->get();
$comments = Comment::replies()->get();
$comments = Comment::recent()->get();

// Relationships
$comment->user;                  // BelongsTo User
$comment->featureRequest;        // BelongsTo FeatureRequest
$comment->parent;                // BelongsTo Comment (parent)
$comment->replies;               // HasMany Comment (replies)

'middleware' => ['web', 'auth', 'custom-middleware'],

use LaravelPlus\FeatureRequests\FeatureRequests;

// Get overall statistics
$stats = FeatureRequests::getStatistics();

// Get vote statistics
$voteStats = FeatureRequests::getVoteStatistics();

// Get category statistics
$categoryStats = FeatureRequests::getCategoryStatistics();
bash
php artisan vendor:publish --provider="LaravelPlus\FeatureRequests\Providers\FeatureRequestsServiceProvider"
bash
php artisan migrate
bash
php artisan feature-requests:create-default-categories

tests/
├── Unit/
│   ├── Models/
│   │   ├── FeatureRequestTest.php
│   │   ├── CategoryTest.php
│   │   ├── VoteTest.php
│   │   └── CommentTest.php
│   ├── Services/
│   └── Repositories/
├── Feature/
│   ├── FeatureRequestControllerTest.php
│   ├── VoteControllerTest.php
│   ├── CommentControllerTest.php
│   └── CategoryControllerTest.php
└── TestCase.php
bash
php artisan vendor:publish --tag=feature-requests-views