Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Makaram's avatar

using camera to capture image in liveiwre

I want to capture an image using camera/web cam of device while using laravel livewire how to do that ?

0 likes
2 replies
alden8's avatar
alden8
Best Answer
Level 1

@makaram

composer require weidner/laravel-webcam
php artisan make:livewire CaptureImage

-- CaptureImage.php

namespace App\Http\Livewire;

use Livewire\Component;
use Weidner\LaravelWebcam\Facades\Webcam;

class CaptureImage extends Component
{
    public $image = null;

    public function takePhoto()
    {
        $this->image = Webcam::take();
        // Optionally save the image to storage or database
    }

    public function render()
    {
        return view('livewire.capture-image');
    }
}

-- resources/views/livewire/capture-image.blade.php

<div>
    <video id="webcam" width="300" height="200" autoplay></video>
    <button wire:click="takePhoto">Take Photo</button>

    @if ($image)
        <img src="{{ $image }}" alt="Captured Image">
    @endif
</div>

-- component for display

<livewire:capture-image />

-- if problem:

--- check for errors in console for library compatibility or configuration issues

--- verify that camera permissions are granted in the browser

--- consult the documentation of laravel-webcam for specific usage details

Reyco's avatar

@alden8 Could not find a matching version of package weidner/laravel-webcam. Check the package spelling, your version constraint and that the package is avail able in a stability which matches your minimum-stability (stable). for Laravel 10

Please or to participate in this conversation.