PHP code example of idoneo / humano-academy
1. Go to this page and download the library: Download idoneo/humano-academy 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/ */
idoneo / humano-academy example snippets
use Idoneo\HumanoAcademy\Models\Course;
$course = Course::create([
'team_id' => 1,
'title' => 'Introduction to Laravel',
'description' => 'Learn the basics of Laravel framework',
'instructor_name' => 'John Doe',
'category_id' => 1, // References categories table
'language' => 'en', // References languages.code
'status' => 'published',
]);
use Idoneo\HumanoAcademy\Models\Chapter;
use Idoneo\HumanoAcademy\Models\Lesson;
$chapter = Chapter::create([
'course_id' => $course->id,
'title' => 'Getting Started',
'order' => 1,
]);
$lesson = Lesson::create([
'chapter_id' => $chapter->id,
'title' => 'Installation',
'description' => 'Learn how to install Laravel',
'video_path' => 'lesson-1-installation.mp4', // Filename only
'duration_minutes' => 15,
'order' => 1,
'status' => 'published',
]);
$lesson->full_video_url
// Returns: http://your-app.test/storage/academy/{team_hash}/videos/lesson-1.mp4
GET /academy # List all courses
GET /academy/list # Alternative route for menu
GET /academy/course/{id} # Course details with lessons
// Relationships
$course->team() // BelongsTo Team
$course->category() // BelongsTo Category
$course->language() // BelongsTo Language
$course->chapters() // HasMany Chapter
$course->lessons() // HasManyThrough Lesson
// Attributes
$course->lectures_count // Total number of lessons
$course->total_duration // Sum of all lesson durations
// Scopes
Course::published() // Only published courses
Course::forTeam($teamId) // Filter by team
$chapter->course() // BelongsTo Course
$chapter->lessons() // HasMany Lesson
$lesson->chapter() // BelongsTo Chapter
$lesson->full_video_url // Computed full video URL
$progress->user() // BelongsTo User
$progress->lesson() // BelongsTo Lesson
$progress->course() // BelongsTo Course (through lesson)
use Spatie\Permission\Models\Role;
$studentRole = Role::firstOrCreate(['name' => 'student']);
$studentRole->givePermissionTo(['academy.list', 'academy.show', 'academy.course.details']);
use Idoneo\HumanoAcademy\Models\Course;
public function index()
{
$courses = Course::published()
->forTeam(auth()->user()->currentTeam->id)
->with(['chapters.lessons', 'category', 'language'])
->orderBy('order')
->get();
return view('your-view', compact('courses'));
}
use Idoneo\HumanoAcademy\Models\Course;
use Idoneo\HumanoAcademy\Models\Chapter;
use Idoneo\HumanoAcademy\Models\Lesson;
public function run()
{
$course = Course::create([
'team_id' => 1,
'title' => 'Laravel Fundamentals',
'description' => 'Complete Laravel course',
'instructor_name' => 'Jane Smith',
'category_id' => 1,
'language' => 'en',
'status' => 'published',
]);
$chapter = Chapter::create([
'course_id' => $course->id,
'title' => 'Introduction',
'order' => 1,
]);
Lesson::create([
'chapter_id' => $chapter->id,
'title' => 'Welcome',
'video_path' => 'welcome.mp4',
'duration_minutes' => 10,
'order' => 1,
'status' => 'published',
]);
}
bash
php artisan academy:install
bash
# Publish and run migrations
php artisan vendor:publish --tag="humano-academy-migrations"
php artisan migrate
# Seed permissions
php artisan db:seed --class="Idoneo\HumanoAcademy\Database\Seeders\AcademyPermissionsSeeder"
bash
php artisan tinker
>>> \App\Models\Team::generateTeamHash(1)
=> "a1b2c3d4e5f6"
bash
php artisan storage:link
blade
@foreach($courses as $course)
<div class="course-card">
<h3>{{ $course->title }}</h3>
<p>{{ $course->description }}</p>
<p>Instructor: {{ $course->instructor_name }}</p>
<p>Duration: {{ $course->total_duration }} minutes</p>
<p>Lessons: {{ $course->lectures_count }}</p>
<a href="{{ route('academy.course.details', $course->id) }}">
View Course
</a>
</div>
@endforeach