lundi 3 février 2020

How to let ID autoincrement start from certain number in Laravel Migration

I want to write a Laravel Migration auto increment ID as a primary key. I want to start this ID with a another value rather than 1. How can I do so ?

The migration up() function:

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('phone');
        $table->rememberToken();
        $table->timestamps();
    });
}


via Chebli Mohamed

Omnipay Paypal Express Chekout Error: Security header is not valid

I have searched around stack overflow and google in general and have not found a problem similar to mine.

The problem is whenever setTestMode() method is used the error "Security header is not valid" pops up, but if I remove it and just keep the setUsername(), setPassword(), and setSignature() methods, it goes through and redirects straight to paypal (Live Paypal).

I am currently using Laravel 5.8 with Omnipay/paypal using Paypal Express Checkout

Here are the files that were used

Paypal.php

public function gateway()
{
    $gateway = Omnipay::create('PayPal_Express');

    $gateway->setUsername(config('services.paypal.username'));
    $gateway->setPassword(config('services.paypal.password'));
    $gateway->setSignature(config('services.paypal.signature'));
    $gateway->setTestMode(config('services.paypal.sandbox'));
    // $gateway->setTestMode(true);

    return $gateway;
}

public function purchase(array $parameters)
{
    $response = $this->gateway()
        ->purchase($parameters)
        ->send();

    return $response;
}

PaypalController.php

public function checkout($order_id)
{
    $order = Order::findOrFail(decrypt($order_id));

    $paypal = new PayPal;

    $response = $paypal->purchase([
        'amount' => $paypal->formatAmount($order->amount),
        'transactionId' => $order->transaction_id,
        'currency' => 'PHP',
        'cancelUrl' => $paypal->getCancelUrl($order),
        'returnUrl' => $paypal->getReturnUrl($order),
        'notifyUrl' => $paypal->getNotifyUrl($order),
    ]);

    if ($response->isRedirect()) {
        $response->redirect();
    }

    return redirect()->back()->with([
            'message' => $response->getMessage(),                
    ]);
}

Here are the contents of the $response

ExpressAuthorizeResponse {#1098 ▼
  #liveCheckoutEndpoint: "https://www.paypal.com/cgi-bin/webscr"
  #testCheckoutEndpoint: "https://www.sandbox.paypal.com/cgi-bin/webscr"
  #request: ExpressAuthorizeRequest {#1095 ▼
    #liveEndpoint: "https://api-3t.paypal.com/nvp"
    #testEndpoint: "https://api-3t.sandbox.paypal.com/nvp"
    #negativeAmountAllowed: true
    #parameters: ParameterBag {#1097 ▶}
    #httpClient: Client {#1063 ▶}
    #httpRequest: Request {#1086 ▶}
    #response: ExpressAuthorizeResponse {#1098}
    #currencies: ISOCurrencies {#1096}
    #zeroAmountAllowed: true
  }
  #data: array:9 [▼
    "TIMESTAMP" => "2020-02-03T11:04:45Z"
    "CORRELATIONID" => "c8d066c9b5ccd"
    "ACK" => "Failure"
    "VERSION" => "119.0"
    "BUILD" => "54118205"
    "L_ERRORCODE0" => "10002"
    "L_SHORTMESSAGE0" => "Security error"
    "L_LONGMESSAGE0" => "Security header is not valid"
    "L_SEVERITYCODE0" => "Error"
  ]
}


via Chebli Mohamed

Browser timeout issue for larger csv files in Laraval

I have a requirement like uploading large csv file and browser shows timeout after some time. I am coding in PHP Laraval. Please help me with some solution.



via Chebli Mohamed

Retrieve data from pivot and their related tables laravel in single query

I have two tables with many to many relationship as follows

Buyer
  - id
  - Name
Book
 - id
 - BookName
Book_Buyer
  - id
  - book_id
  - buyer_id
  - Quantity
  - Price

I need to retrieve Name, BookName, Quantity and Price from this relation through a single query. I need to format the response into JSON where I can show them to yajra datatable

How can I do it? I tried using an array where I pushed them through a single array but I didn't get the result in to the datatable.

$get = Buyer::all()->each(function ($buyer) {
  $buyer->books->map(function ($books) {
    return  $books->pivot;
  });
});

I tried the above solution but it gives me the whole values from database as in relation with pivot. Can anyone suggest the way to do it



via Chebli Mohamed

dimanche 2 février 2020

How to use SwiftMailer plugins in laravel mailable

Here's the SwiftMailer plugin sample code, but it didn't use the laravel mailble.

$decorator = new Swift_Plugins_DecoratorPlugin($replacements);

$mailer->registerPlugin($decorator);
$message = (new Swift_Message())
  ->setSubject('Important notice for {username}')
  ->setBody(
    "Hello {username}, you requested to reset your password.\n" .
    "Please visit https://example.com/pwreset and use the reset code {resetcode} to set a new password."
  );


via Chebli Mohamed

Receive Notificatoin Pusher + Echo in Laravel

I am trying to receive notification using echo + pusher. I can post to pusher and pusher console receive the event and channel but i can't get this data on laravel. I read many document none of work for me.

WebNotification Class // Notification file

private $subscription;
public function __construct($data)
{
    $this->subscription = $data;
}
 public function via($notifiable)
 {
     return ['database','broadcast'];
 }

public function toBroadcast($notifiable)
{
    return new BroadcastMessage([
        'data' => $this->subscription,
        'count' => $notifiable->unreadNotifications->count()
    ]);
}

Account Model

 <?php

 namespace App;

 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Notifications\Notifiable;

 class account extends Model
 {
  use Notifiable;

   public function receivesBroadcastNotificationsOn()
      {
          return 'accounts.'.$this->id;
      }
  }

MyNotification // To call event to send data to pusher

   public function DatabaseNot(){
      $user = Account::where('id', Cookie::get('uid'))->first();
      $data = collect(['title'=>'Hello Title', 'body'=>'my body']);
      $user->notify(new WebNotification($data));

      return view('layout.test',['user'=>$user]);
   } 

Pusher log

     Channel: private-accounts.23, Event: Illuminate\Notifications\Events\BroadcastNotificationCreated

I call Echo in resorces/js/app.js

  Echo.private('App.accounts.23')
   .notification((notification) => {
        console.log(notification.type);
     });

I was not get any response from this. I was already add csrf token in meta, I was compile js code using NPM run watch. I was try men others way no one provide clear document its so much confuse. Please provide me solution



via Chebli Mohamed

laravel shareable form URL

I need to find a way to create a shareable form URL where I can use it to send it to the client(no authentication needed) and the client can fill the form and submit and it would show in my database. My problem with this is not creating the form my problem is how can I create a new shareable form URL that is unique and can only be used once?



via Chebli Mohamed