PHP code example of mydnic / changelog-commit-for-laravel

1. Go to this page and download the library: Download mydnic/changelog-commit-for-laravel 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/ */

    

mydnic / changelog-commit-for-laravel example snippets


return [
    /**
     * The name of the table to store the changelog in.
     */
    'table_name' => 'changelogs',

    /**
     * The GitHub access token to use to fetch the commit history.
     */
    'github_access_token' => env('GITHUB_ACCESS_TOKEN'),

    /**
     * The GitHub repositories to fetch the commit history from.
     */
    'github_repositories' => [
        'mydnic/changelog-commit-for-laravel', // change me
        // other repositories if you want to fetch the commit history from multiple repositories
        // To specify a branch, make it an array like this one below:
        // [ 'mydnic/changelog-commit-for-laravel', 'main' ]
    ],
];

use Mydnic\ChangelogCommitForLaravel\Models\Changelog;

$changelogs = Changelog::latest('date')->paginate(50);

return view('changelog', compact('changelogs'));
// or return JSON response
return response()->json($changelogs);

class ChangelogController
{
    public function __invoke()
    {
        $changelog = DB::table(config('changelog-commit-for-laravel.table_name'))
            ->select('message', 'date', 'branch')
            ->orderBy('date', 'desc')
            ->paginate(10);

        // Group by date
        $groupedChangelog = $changelog->getCollection()->groupBy('date');

        return view('changelog', [
            'groupedChangelog' => $groupedChangelog,
            'pagination' => $changelog // Pass pagination object
        ]);
    }
}
bash
php artisan vendor:publish --tag="changelog-commit-for-laravel-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="changelog-commit-for-laravel-config"
bash
php artisan changelog:fetch
html
<div>
    @foreach ($groupedChangelog as $date => $items)
        <h2 class="text-lg font-semibold text-gray-800 mt-5 mb-1 capitalize">
            {{ \Carbon\Carbon::parse($date)->translatedFormat('l d M Y') }}
        </h2>
        <ul class="list-disc pl-4 text-gray-600 space-y-1">
            @foreach ($items as $item)
                <li class="text-sm">
                    {{ $item->message }}
                </li>
            @endforeach
        </ul>
    @endforeach

    {{-- Laravel Pagination Links --}}
    <div class="mt-10">
        {{ $pagination->links() }}
    </div>
</div>