jeudi 27 septembre 2018

Multiple Laravel App using the same table job

I am working with 3 HTTP servers using the same Laravel app and sharing the same DATABASE, where the first server realize the LoadBalance using nginx, basically with the same weight.

The application works in many queue of jobs using the database's drive on table "jobs". The only server that proccess the jobs (php artisan queue:listen) is the app1.

I would like to know if i can proccess the jobs in the others servers or has some advices about it and if someone had the same experience.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xH24EH
via IFTTT

Laravel: Get softdeleted row in a query builder consult

How do I get a row that was sofdeleted for example This is my code:

$mov = $emp->movimientos()->where('movimiento.linea_id', intval($request->id_caso))->with('producto_nombre', 'costo_promedio');

I have this consult, one movimientos is related with a costo_promedio, but if in some case acosto_promedio is softdeleted the result in my consult $mov will give me null in the part of costo_promedio. The thing is, where do I have to puth the withTrashed() method to get all data even the ones that were softdeleted

Thx for the help



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2DBwUnQ
via IFTTT

Static Variable Not overriding

Class with static variable which is not overriding its value.

My code is

class Export {

protected static $title = '';

public function __construct($title) {
   self::$title = $title;

}

// This event function will trigger every time new instance is created.
public static function event($args)
{
   echo self::$title; // This prints only last assigned value "title2"
}

}

How i called is

$a = new Export('title1'); //in the event function it has to echo "title1" but it is echoing "title2"
$b = new Export('title2');

I cant able to get title1 value in the "event()" method inside the class. anyone help on this.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zzKW54
via IFTTT

PayPal Exception PayPalInvalidCredentialException: Credential not found for default user

I have implemented PayPal (PHP, Laravel) and there is some issue coming while payment. I am getting the following exception in the live.

PayPal\Exception\PayPalInvalidCredentialException: Credential not found for default user. Please make sure your configuration/APIContext has credential information in /var/www/project/project-files/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalCredentialManager.php

I have checked this and other similar problems with the same issue but those didn't helped, i am still missing something. A little help or guidance will be helpful.

The scenario is: Once a user request for Payment, the admin approves it, the payment will be processed.

For this purpose a Laravel Job is created and code for the following Job is:

namespace Test\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use PayPal;
use Test\Models\Transaction;

class ProcessPayout implements ShouldQueue
{

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
 * @var Transaction
 */
protected $transaction;

/**
 * Create a new job instance.
 *
 * @param Transaction $transaction
 */
public function __construct(Transaction $transaction) {
    $this->transaction = $transaction;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle() {
    try {
        \Log::info($this->transaction); // I am getting all the data in this to be processed from Transaction Model

        $response = PayPal::makePayoutEnvironment()
            ->setPayoutEmailSubject($this->transaction->sender_batch_id)
            ->setPayoutItem($this->transaction->receiver, $this->transaction->amount, $this->transaction->sender_item_id)
            ->makePayout();

        if(empty($response)){
            throw new \Exception();
        }

    }catch(\Exception $e){
        \Log::info($e); 
    }
}

}

The PayPal.php is as follows:

namespace Test\PayPal;

use PayPal\Api\Currency;
use PayPal\Api\Payout;
use PayPal\Api\PayoutItem;
use PayPal\Api\PayoutSenderBatchHeader;
use PayPal\Rest\ApiContext;
use ResultPrinter;

class PayPal
{

/**
 * @var ApiContext
 */
protected $context;

/**
 * @var Payout
 */
protected $payout;

/**
 * @var PayoutSenderBatchHeader
 */
protected $senderHeader;

/**
 * PayPal constructor.
 */
public function __construct()
{
    $this->context = app('PayPalContext');
}

/**
 * Create payout environment.
 */
public function makePayoutEnvironment()
{
    $this->payout = new Payout();
    $this->senderHeader = new PayoutSenderBatchHeader();
    return $this;
}

/**
 * Set payout sender email subject.
 *
 * @param      $senderId
 * @param null $subject
 *
 * @return $this
 */
public function setPayoutEmailSubject($senderId, $subject = null)
{
    $this->senderHeader->setSenderBatchId($senderId)
        ->setEmailSubject($subject ?: config('mail.subject_prefix') . 'Payout accepted.');
    $this->payout->setSenderBatchHeader($this->senderHeader);

    return $this;
}

/**
 * Set the payout item with receiver and amount of.
 *
 * @param $receiverEmail
 * @param $amount
 *
 * @param $itemId
 *
 * @return $this
 */
public function setPayoutItem($receiverEmail, $amount, $itemId)
{
    $item = (new PayoutItem())->setRecipientType('Email')
        ->setNote($this->senderHeader->getEmailSubject())
        ->setReceiver($receiverEmail)
        ->setSenderItemId($itemId)
        ->setAmount(new Currency(sprintf('{
                    "value":"%s",
                    "currency":"%s"
                }', $amount, config('currency.fallback'))));

    $this->payout->addItem($item);

    return $this;
}

/**
 * Make payout for recipient.
 *
 * @return bool|\PayPal\Api\PayoutBatch
 */
public function makePayout()
{
    try {
        $output = $this->payout->create(['sync_mod' => false], $this->context);
    } catch (\Exception $ex) {
        \Log::info($ex);
        return false;
    }

    return $output;
}

}

And code for the PayPalServiceProvider is as follows:

namespace Test\Providers;
use Illuminate\Support\ServiceProvider;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
use Test\PayPal\PayPal;
class PayPalServiceProvider extends ServiceProvider
{
    public function boot() {

    }
    public function register()
    {
        $this->app->singleton('PayPalContext', function ($app) {

        $config = array('mode' => 'live');

        $apiContext = new ApiContext(
            new OAuthTokenCredential(
                config('services.paypal.client_id'),// ClientID
                config('services.paypal.client_secret')// ClientSecret
            )
        );

        $apiContext->setConfig($config);

        return $apiContext;
    });

    $this->app->singleton('PayPal', function ($app) {
        return new PayPal();
    });
}

/**
 * Get the services provided by the provider.
 *
 * @return array
 */
    public function provides(){
        return [ 'PayPal' ];
    }
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OUinom
via IFTTT

Manage data in mysql according to dates.

I have a table of crockeries in which i have these columns

    id   name        units
    1    crockery1   100
    2    crockery2   100

And another table of events with these columns

    id   event_name   event_date
    1    event1       18-02-2018
    2    event2       18-02-2018
    3    event3       19-02-2018

Now I want to assign the crockeries to the events. Let's say that I assigned 20 units of crockery1 to event1 which is on date 18-02-1018. So when i assign crockery1 to event2 it should show me 80 units left because event2 is also on the same date as event1 but when i assign crockery1 to event3 it should show 100 units left because event3 is on different date,

So how could I acheive this functionality in PHP.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Oj6nQb
via IFTTT

How to toggle laravel trashed filter off temporarily?

So I've got an A, which has a B that has a C that has a D. I want to go from A to D, but any one (or all) of the objects might have been deleted. So I have to do this:

$d = $a->b()->withTrashed()->first()->c()->withTrashed()->first()->d()->withTrashed()->first()

Which is horrible. I would really rather do this:

turnOffTrashedFilter();
$d = $a->b->c->d;

Does laravel have such an ability?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xU3JWW
via IFTTT

Can't pass associative array to vue

I have array like this.

$array = ['a' => 1, 'b' => 2];

I want to pass it to Vue But it can not.

<my-component :array="'{!! json_encode($array) !!}'"
></my-component>

But the output is show like this in html.

":1,"b":2}'"="">



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zyn0Px
via IFTTT