MarcosKlender

MarcosKlender

Member Since 1 Year Ago

Experience Points 610
Experience Level 1

4,390 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

11 Sep
5 days ago

MarcosKlender left a reply on From Database (Text) To XML

It gives me an error: XML declaration allowed only at the start of the document.

And when I move the $data to the top, it gives me another error: Document is empty.

MarcosKlender started a new conversation From Database (Text) To XML

Hi guys,

In my bdd I have a column (text) called "xml_documento" which store a XML in text format. I need to pass them on a view with all the XML structure. Then I want to change that view with CSS.

Here's my CustomerController.php

<?php

namespace WebServiceApp\Http\Controllers;

use Illuminate\Http\Request;
use WebServiceApp\Customer;
use PDF;

class CustomerController extends Controller
{
  public function export_pdf()
  {
    $data = Customer::select('xml_documento')->get();

    return response()->view('test', compact('data'))->header('Content-Type', 'text/xml');

  }
}

And here's my test.blade.php

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    {{ $data }}
</urlset>

I don't have errors when I refresh the page but the content retrieved from database ($data) still remains as text. I need to transform that text to XML too. Please help! :(

05 Sep
1 week ago

MarcosKlender left a reply on XML To PDF

Can you help me again, please?

I used DomPDF, I read the text field from database and make the XML show in the PDF file but in shows as plain text. Here's my controller:

<?php

namespace WebServiceApp\Http\Controllers;

use Illuminate\Http\Request;
use WebServiceApp\Customer;
use PDF;

class CustomerController extends Controller
{
  public function export_pdf()
  {
    // Fetch all customers from database
    $data = Customer::get();
    // Send data to the view using loadView function of PDF facade
    $pdf = PDF::loadView('test', compact('data'));
    
    $pdf->save(storage_path().'_filename.pdf');

    return $pdf->stream('customers.pdf');
    //return $pdf->download('customers.pdf');
  }
}

And here's my view:

@foreach($data as $customer)
    {{ $customer->xml_documento }}
@endforeach

I need to make that XML to a legible PDF document because it's a bill. :(

04 Sep
1 week ago

MarcosKlender started a new conversation XML To PDF

Hi guys,

I need to convert a XML to PDF in my Laravel Project (5.5). In PostgreSQL, I have a field called XML_document (text). How can I convert the content of that field into a PDF file?

Any thoughts, comments or tips are welcome.

29 Aug
1 year ago

MarcosKlender left a reply on Get And Store Binary Data With A Seed

Mmm... I found out the solution.

$pdf = $document->reporte_pdf;
$my_bytea = stream_get_contents($pdf);

The code above get and transform the binary data correctly.

25 Aug
1 year ago

MarcosKlender started a new conversation Get And Store Binary Data With A Seed

Hi everyone,

I have a problem when I run this seeder.

<?php

use Illuminate\Database\Seeder;
use WebServiceApp\Models\Emproservis;
use WebServiceApp\Models\Production;
use Illuminate\Foundation\Auth\User;
use Carbon\Carbon as Today;

class ProductionSeeder extends Seeder
{
    public function run()
    {
        $hoy = Today::now();
        $hoy = $hoy->format('Y-m-d'); 

        $Production = Production::whereBetween('fecha_emision_documento', ['2018-05-01',$hoy])->get();

        foreach ($Production as $document)
        {
            Emproservis::firstOrCreate(
                [
                    'numero_autorizacion' => $document->numero_autorizacion
                ],
                [
                    'id_documento' => $document->id_documento,
                    'numero_documento' => $document->numero_documento,
                    'ruc_emisor' => $document->ruc_emisor,
                    'tipo_documento_erp' => $document->tipo_documento_erp,
                    'autorizacion_erp' => $document->autorizacion_erp,
                    'clave_acceso' => $document->clave_acceso,
                    'llave_erp' => $document->llave_erp,
                    'tabla_erp' => $document->tabla_erp,
                    'persona_numero' => $document->persona_numero,
                    'persona_nombre' => $document->persona_nombre,
                    'autorizacion_de' => $document->autorizacion_de,
                    'valor_total' => $document->valor_total,
                    'estado_firma' => $document->estado_firma,
                    'usuario_erp' => $document->usuario_erp,
                    'fecha_emision_documento' => $document->fecha_emision_documento,
                    'estacion' => $document->estacion,
                    'xml' => $document->xml,
                    'estado' => $document->estado,
                    'msgsri_tipo' => $document->msgsri_tipo,
                    'msgsri_codigo' => $document->msgsri_codigo,
                    'msgsri_texto' => $document->msgsri_texto,
                    'msgsri_descripcion' => $document->msgsri_descripcion,
                    'ruc_cliente_proveedor' => $document->ruc_cliente_proveedor,
                    'estado_erp' => $document->estado_erp,
                    'fecha_ingreso' => $document->fecha_ingreso,
                    'fecha_firmado' => $document->fecha_firmado,
                    'fecha_envio_recepcion' => $document->fecha_envio_recepcion,
                    'fecha_recepcion' => $document->fecha_recepcion,
                    'fecha_envio_autorizacion' => $document->fecha_envio_autorizacion,
                    'fecha_autorizacion' => $document->fecha_autorizacion,
                    'mensaje_sri' => $document->mensaje_sri,
                    'xml_documento' => $document->xml_documento,
                    'reporte_pdf' => $document->reporte_pdf // Here's the error
                ]);
        }
    }
}

The seeder extract all fields correctly, but the last field "reporte_pdf" extract null or other invalid data. I use PostgreSQL and that field is bytea type (it contents binary data). Someone know how to solve this problem?

02 Aug
1 year ago

MarcosKlender started a new conversation Laravel Seed To Make Insert From Another Database

Hi everyone,

I have the following SQL ERROR

SQLSTATE[22001]: String data, right truncated: 7 ERROR:  value too long for type character varying(37)

I made a seeder to extract rows from a remote database and insert them in my local database, like a replica. I don't know what I'm doing wrong, please help! :(

Here's my ProductionSeeder.php

<?php

use Illuminate\Database\Seeder;
use WebServiceApp\Models\Emproservis;
use WebServiceApp\Models\Production;
use Illuminate\Foundation\Auth\User;

class ProductionSeeder extends Seeder
{
    public function run()
    {
        $Production = Production::whereBetween('fecha_emision_documento', ['2018-01-01', '2018-01-02'])->get();

        foreach ($Production as $document)
        {
            Emproservis::firstOrCreate(
                [
                    'numero_autorizacion' => $document->numero_autorizacion,
                ],
                [
                    'id_documento' => $document->id_documento,
                    'numero_documento' => $document->numero_documento,
                    'ruc_emisor' => $document->ruc_emisor,
                    'tipo_documento_erp' => $document->tipo_documento_erp,
                    'autorizacion_erp' => $document->autorizacion_erp,
                    'clave_acceso' => $document->clave_acceso,
                    'llave_erp' => $document->llave_erp,
                    'tabla_erp' => $document->tabla_erp,
                    'persona_numero' => $document->persona_numero,
                    'persona_nombre' => $document->persona_nombre,
                    'autorizacion_de' => $document->autorizacion_de,
                    'valor_total' => $document->valor_total,
                    'estado_firma' => $document->estado_firma,
                    'usuario_erp' => $document->usuario_erp,
                    'fecha_emision_documento' => $document->fecha_emision_documento,
                    'estacion' => $document->estacion,
                    'xml' => $document->xml,
                    'estado' => $document->estado,
                    'msgsri_tipo' => $document->msgsri_tipo,
                    'msgsri_codigo' => $document->msgsri_codigo,
                    'msgsri_texto' => $document->msgsri_texto,
                    'msgsri_descripcion' => $document->msgsri_descripcion,
                    'ruc_cliente_proveedor' => $document->ruc_cliente_proveedor,
                    'estado_erp' => $document->estado_erp,
                    'fecha_ingreso' => $document->fecha_ingreso,
                    'fecha_firmado' => $document->fecha_firmado,
                    'fecha_envio_recepcion' => $document->fecha_envio_recepcion,
                    'fecha_recepcion' => $document->fecha_recepcion,
                    'fecha_envio_autorizacion' => $document->fecha_envio_autorizacion,
                    'fecha_autorizacion' => $document->fecha_autorizacion,
                    'mensaje_sri' => $document->mensaje_sri,
                    'xml_documento' => $document->xml_documento,
                    'reporte_pdf' => $document->reporte_pdf
                ]);
        }
    }
}

Here's my model for the local database.

<?php

namespace WebServiceApp\Models;

use Illuminate\Database\Eloquent\Model;

class Emproservis extends Model
{
    protected $connection = 'pgsql';
    protected $table = 'de01_xml';

    protected $primaryKey = 'pk_de01_xml';
    protected $keyType = 'character varying';
    public $incrementing = false;
    public $timestamps = false;

    protected $fillable = [
        'numero_autorizacion', 'id_documento', 'numero_documento', 'ruc_emisor', 'tipo_documento_erp',
        'autorizacion_erp', 'clave_acceso', 'llave_erp', 'tabla_erp', 'persona_numero', 'persona_nombre',
        'autorizacion_de', 'valor_total', 'estado_firma', 'usuario_erp', 'fecha_emision_documento',
        'estacion', 'xml', 'estado', 'msgsri_tipo', 'msgsri_codigo', 'msgsri_texto', 'msgsri_descripcion',
        'ruc_cliente_proveedor', 'estado_erp', 'fecha_ingreso', 'fecha_firmado', 'fecha_envio_recepcion',
        'fecha_recepcion', 'fecha_envio_autorizacion', 'fecha_autorizacion', 'mensaje_sri', 'xml_documento', 'reporte_pdf'
    ];
}

And this is for the remote database.

<?php

namespace WebServiceApp\Models;

use Illuminate\Database\Eloquent\Model;

class Production extends Model
{
    protected $connection = 'pgsql2';
    protected $table = 'de01_xml';
    
    protected $primaryKey = 'pk_de01_xml';
    protected $keyType = 'character varying';
    public $incrementing = false;
    public $timestamps = false;
}
03 Jul
1 year ago

MarcosKlender left a reply on Best Way To View A PDF File In A New Tab

The solution for me was edit my DocumentsController.php like this:

public function pdf($id)
{
        $base64 = Emproservis::where('numero_autorizacion', $id)->firstOrFail();
        $pdf = $base64->reporte_pdf;        
        $my_bytea = stream_get_contents($pdf);

        $decoded = base64_decode($my_bytea);
        $file = "$base64->numero_documento.pdf";
        file_put_contents($file, $decoded);

    return response()->file($file)->deleteFileAfterSend(true);
}

MarcosKlender left a reply on Create Users In Database From Another Table

I chose to use a seeder as a solution to this problem. Here is my default DatabaseSeeder.php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Auth\User;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $Emproservis = DB::table('de01_xml')->select('persona_nombre', 'ruc_cliente_proveedor')->distinct()->get();

        foreach ($Emproservis as $client)
        {
            User::firstOrCreate
            ([
                'name' => $client->persona_nombre,
                'email' => str_random(10),
                'ruc_o_ci' => $client->ruc_cliente_proveedor,
                'password' => bcrypt($client->ruc_cliente_proveedor)
            ]);
        }
    }
}

MarcosKlender left a reply on Skip Data And Add New Rows In Database

Man, you're awesome! I search a lot and I never find an example like this. Thanks! (:

MarcosKlender started a new conversation Skip Data And Add New Rows In Database

Hi everyone,

This is my default DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Auth\User;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $Emproservis = DB::table('de01_xml')->select('persona_nombre', 'ruc_cliente_proveedor')->distinct()->get();

        foreach ($Emproservis as $client)
        {
            User::firstOrCreate
            ([
                'name' => $client->persona_nombre,
                'email' => str_random(10),
                'ruc_o_ci' => $client->ruc_cliente_proveedor,
                'password' => bcrypt($client->ruc_cliente_proveedor)
            ]);
        }
    }
}

I have 27000 clients, when I run the seeder once, it creates the users normally. During this process I use Ctrl + C to stop the seeding and, for example, 100 users was created.

When I run the seeder again I receive the following SQL error:

SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "users_ruc_o_ci_unique"

I need the seeder SKIP the 100 users created and insert again from the user 101. Please help! :(

02 Jul
1 year ago

MarcosKlender left a reply on Make A Db Seed Without Duplication

The field "ruc_o_ci" must be unique, I want to add new users using that seeder without duplicate errors. :(

MarcosKlender started a new conversation Make A Db Seed Without Duplication

Hi everyone,

I'm creating a seed to make users with data from other table.

Here's my default DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Auth\User;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        $Emproservis = DB::table('de01_xml')->select('persona_nombre', 'ruc_cliente_proveedor')->distinct()->get();

        foreach ($Emproservis as $client)
        {
            User::firstOrCreate
            ([
                'name' => $client->persona_nombre,
                'email' => str_random(10),
                'ruc_o_ci' => $client->ruc_cliente_proveedor,
                'password' => bcrypt($client->ruc_cliente_proveedor)
            ]);
        }
    }
}

When I make this seed again I receive the following SQL error:

SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "users_ruc_o_ci_unique"

I thought the "firstOrCreate" function was the solution but the error is still there. Can somebody help me?

26 Jun
1 year ago

MarcosKlender left a reply on Create Users In Database From Another Table

But, the problem is that other table is huge. It's a .backup, not a model made with Laravel.

And the ID's are repeated several times, I need to use a function like the SQL "DISTINCT" to extract just one client that repeats and create the user in create_users_table. :(

MarcosKlender started a new conversation Create Users In Database From Another Table

Hi everyone,

How can I create users from another table to the make:auth table?

In the other table I have data of clients like:

|-------------------|
|   COLUMNS         |
|-------------------|
|   client_name     |
|   client_address  |
|   client_ID       |
|   client_phone    |
|-------------------|

Here's my create_users_table that make:auth creates

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name'); // From client_name
            $table->string('email')->unique();
            $table->string('ruc_o_ci')->unique();   // From client_ID
            $table->string('password'); // From client_ID
            $table->rememberToken();
            $table->timestamps();
            $table->boolean('admin')->default(0);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

I want to pass the column "client_name" as "name" and "client_ID" as both "ruc_o_ci" and "password". Of course, the "ID" needs to be bcrypted for the "password" field.

I hope you can help me. :(

18 Jun
1 year ago

MarcosKlender started a new conversation Default Authentication CSS

Hi everyone,

I just created a login with "php artisan make:auth" and many files was created.

One of those was app.css and this is the content:

@import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600);/*!
 * Bootstrap v3.3.7 (http://getbootstrap.com)
 * Copyright 2011-2016 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 */

/*! normalize.css v3.0.3 | MIT License | etc etc etc...

/*! Source: https://github.com/h5bp/html5 etc etc etc...

This file use Bootstrap v3.3.7, how can I update the file to use a newer version like v4.1?

14 May
1 year ago

MarcosKlender started a new conversation Best Way To View A PDF File In A New Tab

Hi everyone,

I have a function that retrieve a base64 data, transform to pdf file and force download when I click in the pdf icon. How can I preview that pdf before download? And how can I change the name of the downloaded file?

Here is the table from invoice.blade.php

<table class="table table-hover table-responsive" id="tabla_documentos">
    <thead>
      <tr>
        <th scope="col">Tipo</th>
        <th scope="col">Cliente</th>
        <th scope="col">RUC/CI</th>
        <th scope="col">Estado</th>
        <th scope="col">Número</th>
        <th scope="col">Valor</th>
        <th scope="col">Fecha Emisión</th>
        <th scope="col">Fecha Autorización</th>
        <th scope="col">XML</th>
        <th scope="col">PDF</th>
      </tr>
    </thead>
    <tbody>
      @foreach($factura as $value)
      <tr>
        <td>{{ $value->id_documento }}</td>
        <td>{{ $value->persona_nombre }}</td>
        <td>{{ $value->ruc_cliente_proveedor }}</td>
        <td>{{ $value->estado }}</td>
        <td>{{ $value->numero_documento }}</td>
        <td>{{ $value->valor_total }}</td>
        <td>{{ $value->fecha_emision_documento }}</td>
        <td>{{ $value->fecha_autorizacion }}</td>
        <td><a href="{{ route('ruta.documentos.xml', $value->numero_autorizacion) }}" target="_blank"><i class="far fa-file-code fa-lg"></i></td>
        <!-- This is the PDF icon -->
        <td><a href="{{ route('ruta.documentos.pdf', $value->numero_autorizacion) }}" target="_blank"><i class="far fa-file-pdf fa-lg"></i></a></td>
      </tr>
      @endforeach
    </tbody>
  </table>

The PDF function from DocumentsController.php

public function pdf($id)
{
    $pdf = Emproservis::where('numero_autorizacion', $id)->firstOrFail();
    $base64 = $pdf->reporte_pdf;        
    $my_bytea = stream_get_contents($base64);  //This transform the bytea data to string. Is this ok?

    $decoded = base64_decode($my_bytea);
    $file = 'invoice.pdf'; //I want to name the file dynamically
    file_put_contents($file, $decoded);

    if (file_exists($file))
    {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        readfile($file);
        exit;
    }
}

And the web route from web.php

Route::get('/home/descargar/pdf/{id}', '[email protected]')
    ->name('ruta.documentos.pdf');
10 May
1 year ago

MarcosKlender left a reply on Select A Specific Row From View And Show That File

It works! Thanks a lot, man. :)

MarcosKlender left a reply on Select A Specific Row From View And Show That File

I found a value to uniquely identify each invoice. How do I pass that unique id to the controller?

{{ $value->numero_autorizacion }}

MarcosKlender started a new conversation Select A Specific Row From View And Show That File

Hi everyone,

I have a table that show invoices of the client logged and I want to show the XML file of the invoice. I don't know how to reference the specific file from a row, when I click on the XML icon it show me all invoices at once. I don't know if I need AJAX or JSON to retrieve the specific XML file from the row clicked.

Here is the table from invoice.blade.php

<table class="table table-hover table-responsive" id="tabla_documentos">
    <thead>
      <tr>
        <th scope="col">Tipo</th>
        <th scope="col">Cliente</th>
        <th scope="col">RUC/CI</th>
        <th scope="col">Estado</th>
        <th scope="col">Número</th>
        <th scope="col">Valor</th>
        <th scope="col">Fecha Emisión</th>
        <th scope="col">Fecha Autorización</th>
        <th scope="col">XML</th>
        <th scope="col">PDF</th>
      </tr>
    </thead>
    <tbody>
      @foreach($factura as $value)
      <tr>
        <td>{{ $value->id_documento }}</td>
        <td>{{ $value->persona_nombre }}</td>
        <td>{{ $value->ruc_cliente_proveedor }}</td>
        <td>{{ $value->mensaje_sri }}</td>
        <td>{{ $value->numero_documento }}</td>
        <td>{{ $value->valor_total }}</td>
        <td>{{ $value->fecha_emision_documento }}</td>
        <td>{{ $value->fecha_autorizacion }}</td>
        <!-- The <td> below is the XML icon -->
        <td><a href="{{ route('ruta.documentos.xml') }}" target="_blank"><i class="far fa-file-code"></i></td>
        <td><a href="{{ route('ruta.documentos.pdf') }}" target="_blank"><i class="far fa-file-pdf"></i></a></td>
      </tr>
      @endforeach
    </tbody>
  </table>

The XML function from DocumentsController.php

public function xml()
{
    $ruc_usuario = Auth::user()->ruc_o_ci;

    $xml = Emproservis::where([
            ['ruc_cliente_proveedor', '=', $ruc_usuario],
        ])->orderBy('fecha_emision_documento', 'desc')->get();
    return response()->view('documento', compact('xml'))->header('Content-Type', 'text/xml');
}

And the web route from web.php

Route::get('/home/descargar/xml', '[email protected]')
    ->name('ruta.documentos.xml');