Support for Judge0 API to run/judge code in different languages
mouadbnl/laravel-judge0 is a Laravel package for support for judge0 api to run/judge code in different languages.
It currently has 10 GitHub stars and 23 downloads on Packagist (latest version 0.4.2).
Install it with composer require mouadbnl/laravel-judge0.
Discover more Laravel packages by mouadbnl
or browse all Laravel packages to compare alternatives.
Last updated
Judge0 API integration for running/judging code with different languages
use Mouadbnl\Judge0\Models\Submission;
$submission = Submission::create([
'language_id' => 54, // C++ (GCC 9.2.0)
'source_code' =>'
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
cin >> s;
cout << "the value you entered is : " << s;
return 0;
}
'
])
->setInput('judge0')
->setExpectedOutput('the value you entered is : judge0')
->setTimeLimit(1) // seconds
->setMemoryLimitInMegabytes(256)
->submit();
You can install the package via composer:
composer require mouadbnl/laravel-judge0
You can publish and run the migrations with:
php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-config"
First add Submitter trait to the User Model.
use Mouadbnl\Judge0\Traits\Submitter;
class User extends Authenticatable
{
use Submitter;
/** **/
}
This create a polymorphique relationship between the User model and the Submission model provided by this package. You can let the User make a submission using the follwing code:
$user = User::firstOrFail();
$user->submissions()->create([
'language_id' => 54, // C++ (GCC 9.2.0)
'source_code' =>'
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
cin >> s;
cout << "the value you entered is : " << s;
return 0;
}
'
])
->setInput('judge0')
->setExpectedOutput('the value you entered is : judge0')
->setTimeLimit(1) // seconds
->setMemoryLimitInMegabytes(256)
->submit();
This package provides two drivers to connect to judge0 API
This allows you to connect to a judge0 Docker instance. to do so please define the JUDGE0_BASE_URI which is the url to your instance and JUDGE0_KEY which it the API key to authenticate in your environment variables or .env file.
JUDGE0_BASE_URI=localhost:2358
JUDGE0_KEY=yout_key
This allows you to connect to the the Judge0 app on RapidAPI.
For this you need to define the following in your environment variables or .env file.
JUDGE0_RAPIDAPI_BASE_URI the rapidapi url to make the requests to, which it by default https://judge0-ce.p.rapidapi.com.JUDGE0_RAPIDAPI_HOST, by default it is judge0-ce.p.rapidapi.com.JUDGE0_RAPIDAPI_KEY yout rapidapi key.JUDGE0_RAPIDAPI_BASE_URI=https://judge0-ce.p.rapidapi.com
JUDGE0_RAPIDAPI_HOST=judge0-ce.p.rapidapi.com
JUDGE0_RAPIDAPI_KEY=yout_key
composer test
The MIT License (MIT). Please see License File for more information.