On click of the button initiate an ajax call
$("#button").on("click", function () {
url: window.location.origin + '/fetch-git-commits',
type: "get",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function (data) {
// data contains the git commit informations
$(".container").html(data);
}
});
In the Route.php file add an entry
Route::get('fetch-git-commits', 'YourController@getGitCommits');
In the controller
public function getGitCommits ()
{
exec('git log', $output);
$history = array();
foreach($output as $line) {
if(strpos($line, 'commit') === 0) {
if(!empty($commit)) {
array_push($history, $commit);
unset($commit);
}
$commit['hash'] = substr($line, strlen('commit'));
}
else if(strpos($line, 'Author') === 0) {
$commit['author'] = substr($line, strlen('Author:'));
}
else if(strpos($line, 'Date') === 0) {
$commit['date'] = substr($line, strlen('Date:'));
}
else {
if(isset($commit['message']))
$commit['message'] .= $line;
else
$commit['message'] = $line;
}
}
return $history; // Array of commits, parse it to json if you need
}
References:
Reading a git commit message from php
Parse git log with PHP to an array