phplaravelpoint-of-salethermal-printer

How to use ecspos-php in laravel 5.4?


I say thank you before, I hope you can help my problem, this's my first time using framework laravel 5.4 in case of struk printing with windows 7 operating system and using epson U220 which printer connected with USB locally, but when i'm try to access page and click button print, printer doesn't action print page.

Controller

<?php

    namespace App\Http\Controllers;

    use App\Pembayaran;
    use Illuminate\Http\Request;
    use Yajra\DataTables\DataTables;
    use Mike42\Escpos\Printer; 
    use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
    use Mike42\Escpos\PrintConnectors\FilePrintConnector;
    use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;

    class PembayaranController extends Controller
    {
        public function print(Request $request)
        {
            try {
                $connector = new WindowsPrintConnector("\\wind7\usb\epson");
                $printer = new Escpos($connector);
                $printer -> text("Hello World!\n");
                $printer -> cut();

                $printer -> close();
            } catch(Exception $e) {
                echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
            }
        }
    }

Route

<?php

Auth::routes();

Route::get('/', function () {
    return redirect()->route('home');
});
Route::get('/home', 'HomeController@index')->name('home');
Route::post('/pembayaran/print', 'PembayaranController@print')->name('pembayaran.print');

Blade

<form action="{{ route('pembayaran.print') }}" method="POST">
            <input type="text" name="username" class="form-control">
            <input type="hidden" name="_token" class="form-control" value="{!! csrf_token() !!}">
            <button type="submit" name="submit" class="btn btn-info">Print</button
</form>

Solution

  • The share name should be passed to the WindowsPrintConnector as the first argument, instead:

    For instance:

    $connector = new WindowsPrintConnector("epson U220");
    

    If the share name was epson U2020