Skip to content

Using It From Code

Damilola Ogunsakin edited this page Oct 15, 2026 · 5 revisions

Using It From Code

Everything the studio does is available through the VideoDemo facade, so you can build your own screens, make videos from your own jobs, or skip the studio.

use Ogunsakin01\VideoDemo\Facades\VideoDemo;

// Queue a video. Every option is optional; a bad one throws InvalidArgumentException.
$video = VideoDemo::make('How a manager approves a holiday request', [
    'title' => 'Approve a holiday request',
    'start' => '/time-off',
    'length' => 60,               // seconds
    'style' => 'spotlight',       // a style key or name
    'devices' => ['desktop', 'mobile'],
    'model' => 'claude-sonnet-5-5',
    'max_cost' => 0.50,           // US dollars
    'max_steps' => 20,
    'speed' => 1.5,
    'as' => 'manager',            // a user type, 'guest', or a user id or email
    'sample_data' => true,        // the default; false records on your own local data
    'voice' => 'kokoro:af_heart', // a voice-over; VideoDemo::voices() lists them
    'language' => 'fr',           // the app's pages' language when left out
    'music' => 'brand',           // a music track; VideoDemo::music() lists them
    'private' => false,
    'queue' => true,              // false makes it now, in this process
]);

Managing videos

VideoDemo::estimate('claude-sonnet-5-5', 'medium', 60);  // ['low' => …, 'expected' => …, 'high' => …]
VideoDemo::stop($video);
VideoDemo::retry($video);                         // a new plan
VideoDemo::retry($video, sampleData: true);       // switch to sample data (always a new plan)
VideoDemo::rerecord($video, speed: 1.0);          // the same plan again, at no AI cost
VideoDemo::updatePlan($video, ['steps' => $steps]); // a plan edited by hand; throws InvalidArgumentException with what's wrong
VideoDemo::verify($video);                        // does it still work? ['ok' => false, 'step' => 3, 'device' => 'mobile', 'error' => …]
VideoDemo::translate($video, 'fr');               // the same video in French, made from its plan (queued)
VideoDemo::export($video, 'gif');                 // the path of a GIF, 'square' or 'vertical' copy
VideoDemo::publish($video);                       // or unpublish()
VideoDemo::embeds($video);                        // where your code shows it: [['file' => …, 'line' => …, 'text' => …]]
VideoDemo::delete($video);                        // its recordings, and its library files if published

VideoDemo::videos();                              // every video, newest first
VideoDemo::find('approve-a-holiday-request');     // by id or slug

Reading the library

VideoDemo::library('public');                     // published videos, as the library shows them
VideoDemo::search('holiday');
VideoDemo::url($entry, 'video', 'mobile');        // a published video's MP4, poster or subtitles address
VideoDemo::forPage('jobs.create');                // the videos that show a page, by route name or path; the current route when left out

These work without the studio, so you can use them in production.

Everything else

VideoDemo::suggest();                             // ideas from the AI, saved
VideoDemo::ideas();
VideoDemo::styles();
VideoDemo::userTypes();                           // the user types found from your roles
VideoDemo::models();
VideoDemo::pages(as: 'manager');                  // pages that user type can open, with their headings
VideoDemo::checkPages(['/time-off', '/reports'], as: 'manager');  // broken pages, at no AI cost

The model and the events

Ogunsakin01\VideoDemo\Models\Video is an Eloquent model with the status, plan, cost, log and recordings, so you can query it like any other.

When a video's status changes, the package fires Ogunsakin01\VideoDemo\Events\VideoStatusChanged with the video and its old and new status. Listen for it to send a notification when a video is ready:

use Ogunsakin01\VideoDemo\Enums\VideoStatus;
use Ogunsakin01\VideoDemo\Events\VideoStatusChanged;

Event::listen(function (VideoStatusChanged $event) {
    if ($event->to === VideoStatus::Ready) {
        // notify someone, publish it, …
    }
});

When a check finds that a video no longer works (video-demo:verify, Does it still work? or VideoDemo::verify()), the package fires Ogunsakin01\VideoDemo\Events\VideoBroke with the video and the result: the step, device, error and url.

Clone this wiki locally