TalentLMS is a learning management system. Companies use it to give online courses to their staff, partners and customers. Often, these people already have an account in a different application. The company does not want them to sign up two times.
For one of our clients, the Laravel application controls who gets access to which course. It creates the learner in TalentLMS and enrolls them. We put this code in a package: Laravel TalentLMS.
What the package does
Laravel TalentLMS gives a small, typed client for the TalentLMS API.
- It reads users, courses and groups.
- It finds a user by email address or by username.
- It creates users and groups.
- It enrolls a user in a course, as a learner or an instructor, and removes them again.
- It adds a user to a group, and removes them again.
- It gets a login link that sends a user directly to a course.
- It changes each response into a data object with typed properties and dates.
Install the package
composer require bernskiold/laravel-talentlms
Add your API key and the address of your TalentLMS domain to the .env file. You find the API key in the TalentLMS account settings.
TALENTLMS_API_KEY=your-api-key
TALENTLMS_DOMAIN=https://yourcompany.talentlms.com
Find or create a user
All calls start on the TalentLms facade. First, try to find the user. If the user does not exist, create the user.
use Bernskiold\LaravelTalentLms\Facades\TalentLms;
$learner = TalentLms::users()->lookupByEmail($user->email)
?? TalentLms::users()->create(
firstName: $user->first_name,
lastName: $user->last_name,
email: $user->email,
);
If you do not give a username, the package uses the email address. If you do not give a password, the package makes a long random password. The user does not need it, because they sign in through your application. Keep the TalentLMS user ID on your own user model. Then you do not need to look up the user each time.
Read the progress of a user
Use get() to read one user. The user object includes the courses, groups, branches and certifications of the user.
$learner = TalentLms::users()->get($user->talentlms_id);
foreach ($learner->courses as $course) {
$course->completionStatus; // For example "completed"
$course->completionPercentage; // For example 75.0
$course->completedAt; // A Carbon date, or null
}
The dates are Carbon objects, so you can format and compare them directly.
Enroll a user in a course
Give the course and the user. You can use IDs, or a course name and an email address.
TalentLms::courses()->enrollUser($courseId, $user->email);
To add the user as an instructor, set the third argument to true. To remove the user from the course, use unenrollUser().
Send the user directly to the course
A learner should not need a second password. Get a login link for the course, and redirect the user to it:
$url = TalentLms::courses()->courseLoginUrl($learnerId, $courseId);
return redirect()->away($url);
The link signs the user in to TalentLMS and opens the course.
Use groups
In TalentLMS, a group can give access to many courses at the same time. The package can create groups and change who is in them:
$group = TalentLms::groups()->create('Partner training 2025');
TalentLms::groups()->addUser($group, $learnerId);
A limit to know
The package does not cover the full TalentLMS API. It covers users, courses and groups, which is what our client needed. When the API returns an error, the client sends a Laravel HTTP RequestException. Only the lookup methods catch the error and return null. Catch the exception in your own code where an error is possible.
Get the package
Laravel TalentLMS is open source, with the MIT license. The code is on GitHub. If you need an endpoint that is not in the package, open an issue or send a pull request. We are happy to hear from you.