mercredi 17 août 2022

How I can convert a dynamic blade content into PDF with mPDF in Laravel 7?

This my frontend.create-cv.pdf.blade.php :

<section>

    <h1>Language</h1>

    @foreach ($data['languages'] as $lang)

        <em> | </em>

    @endforeach

</section>

And this is my controller :

$data['languages'] = language_skill::where('jobseeker_id', $id)->get();

$mpdf->WriteHTML(view('frontend.create-cv.pdf', ['data' => $data]));

I'm geting this error :

Undefined variable: data (View: E:\xampp\htdocs\rzgroup.az\resources\views\frontend\create-cv\pdf.blade.php)`

How can i solve this problem ?



via Chebli Mohamed

mardi 16 août 2022

I received email with subject LARAVEL SMTP CRACK | HOOST

Today i get email with subject "LARAVEL SMTP CRACK | HOOST" I use laravel framework 5.8. My .env include

APP_ENV = production
APP_DEBUG = false

and

MAIL_DRIVER=smtp
MAIL_HOST=smtp.domain.site
MAIL_PORT=2525
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=tls

what can i do ? was my site hacked?



via Chebli Mohamed

lundi 15 août 2022

Laravel v5.5 echo doesn't catch event and pusher doesn't broadcast event

I am currently unable to BOTH listen to events or use the pusher to broadcast events.

Issue

  1. I have the payload messages being generated in laravel log but it doesnt appear on the pusher debugging site.

  2. In terms of receiving the event, the echo listener doesn't get triggered when a message is sent on the pusher debugging site although there I am already subscribed to it. enter image description here

Front End (Echo)

 $(document).ready(function() {
            window.Echo.private('scannedUpdate')
            .listen('scannedQR', (e) => {
                console.log("fight back");
                alert('fight back');
            });
        });

Event

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class scannedQR implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $username;
    public $message;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($username)
    {
        error_log("Made it");
        $this->username = $username;
        $this->message = $username . " has scanned qr code";
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        error_log("Entered broadcast on");
        return new PrivateChannel('scannedUpdate');
        
        // return 'scannedQR';
    }

    public function broadcastAs()
    {
        error_log("In broadcast as");
        return 'scannedQR';
    }
}

Route (Trigger Event)

Route::get('/chatbot/test', function () {
    broadcast(new scannedQR('Cheese'));
    return "Event has been sent!";
});

Laravel Log

local.INFO: Broadcasting [scannedQR] on channels [private-scannedUpdate] with payload:
{
    "username": "Cheese",
    "message": "Cheese has scanned qr code",
    "socket": null
}  

Bootstrap.js

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Lover = "LOVER!";

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'key',
    // cluster: 'mt1',
    cluster:'ap1',
    encrypted: true
});

Channels (Never gets called)

Broadcast::channel('scannedUpdate', function ($user) {
    error_log("Within channel");
    return true;
});


via Chebli Mohamed

mercredi 10 août 2022

How to Mock environment in Laravel 5.7

I'm trying to implement a unit test in Laravel 5.7 I want to mock APP_ENV testing to production or any else as I want.

Unit test code:

App::shouldReceive('environment')->with('APP_ENV')->once()->andReturn('production');

Code:

if (in_array(env('APP_ENV'), ["production", 'local'])) {
    return "This production environment";
}

There was 1 error:

Mockery\Exception\BadMethodCallException: Received Mockery_5_Illuminate_Foundation_Application::offsetGet(), but no expectations were specified


via Chebli Mohamed

created_at and updated_at columns not updated by updateorcreate - Laravel Eloquent

Hey All I am new to Laravel. I have a table called dsp_account_fee. enter image description here enter image description here

This is what I have in my Model.

{
    use AdvancedInserts;

    protected $table = "dsp_account_fee";
    protected $primaryKey = 'dsp_account_id';
    protected $secondaryKey = 'screen_type';


    public $timestamps = false;

    protected function setKeysForSaveQuery(Builder $query)
    {
        parent::setKeysForSaveQuery($query);
        $query->where($this->secondaryKey, '=', $this->{$this->secondaryKey});
        return $query;
    }

    protected $fillable = array(
        'dsp_account_id', 'screen_type', 'pmp_percent' , 'omp_percent'
    );

}

When I create or update record I use the updateorcreate method like this:

$res1 = DspAccountFee::updateOrCreate(
                ['dsp_account_id' => $dsp_account_id, 'screen_type' => 'ctv'],
                ['pmp_percent' =>$fields['fee_ctv_pmp_percent'], 'omp_percent' => $fields['fee_ctv_omp_percent']]
                );

The problem is that the created_at and the updated_at not filled automatically and stay null. what I am missing?



via Chebli Mohamed

UpdateOrCreate not updating data - Laravel Eloquent

I am new to laravel. I have an issue when I am trying to update or create record in DB. I have a table called DspAccountFee with this columns: enter image description here

I want to create record of dsp_account_id + screen_type when the combination not exists, and to update if the combination exists. this is my code: (just tried to update the first row keys of -> dsp_account_id(5187) + screen type (ctv). However nothing changed.

DspAccountFee::updateOrCreate(
                ['dsp_account_id' => $dsp_account_id, 'screen_type' => 'ctv'],
                ['pmp_percent' =>$fields['fee_ctv_pmp_percent'], 'omp_percent' => $fields['fee_ctv_omp_percent']]
                );

When I print the values before the DB operation they exists:

\Log::info("dsp_account:");
\Log::info($dsp_account_id);
\Log::info("ctv pmp percent:");
\Log::info($fields['fee_ctv_pmp_percent']);
\Log::info("ctv omp percent:");
\Log::info($fields['fee_ctv_omp_percent']);
\Log::info("app pmp percent:");

enter image description here

What I am missing why it is not update the db? Nothing in logs and No exception

this is my method in the model

protected $fillable = array(
        'dsp_account_id', 'screen_type'
    );


via Chebli Mohamed

lundi 8 août 2022

Google Authentication Login in Laravel 5.4

Client error: GET https://www.googleapis.com/plus/v1/people/me?prettyPrint=false resulted in a 403 Forbidden response: { "error": { "code": 403, "message": "Legacy People API has not been used in project 536929073653 before or it (truncated...) enter image description here



via Chebli Mohamed