samedi 1 avril 2017

Laravel 5.4 TokenMismatchException in VerifyCsrfToken.php line 68 on some device

I know it's one of the most asked question around here, but I really read everything on the first 10 pages results on google and nothing solved my problem.

On a fresh installation of laravel 5.4 , generated the auth controller, views, etc. via php artisan make:auth when I try to register (or login) in some device I get the following error:

TokenMismatchException in VerifyCsrfToken.php line 68

I'm running this application in local on debian 8.7 and php7 (could it be related to the problem in some way ?) From my pc, iphone 7, another windows 10 desktop it works perfectly, but on a Huawei p8 lite, ipad 2 and lubuntu (quite old version) I get that error. So it's really weird because it just happends with some device (no matter whaht O.S. no matter what browser).

I can already tell you that I tried grant permissions to sessions folder, change session_domain, clearing cache (but as I said I'm trying this on a fresh installation), change to {!! csrf_token !!} , etc.

Just to give you more information about my system, this is the php version i'm using:

php --version
PHP 7.0.17-1~dotdeb+8.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.17-1~dotdeb+8.1, Copyright (c) 1999-2017, by Zend 
Technologies

I'm really stuck on this for days. Got no more ideas.



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

Get json via laravel command - Failed to open stream

I am writing a laravel command to read in reddit comments. I am running Laravel Framework version 5.2.45. My handle method looks like the following:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class reddit extends Command
{
    /**...**/
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $str = json_decode(file_get_contents('http://ift.tt/2olu9hs'));
        foreach ($str as $comments) {
            // dd($comments);
            foreach ($comments->data->children as $comment) {
                if ($comment->body_html == 'You') {
                    print_r($comment);
                } else {
                    print_r($comment);
                }
            }
        }
    }
}

When executing the command I get the following error message:

[ErrorException]
file_get_contents(http://ift.tt/2olu9hs): failed to open stream: No such file or directory

Any suggestions what I am doing wrong?

I appreciate your replies!



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

In laravel SPA, I use the DataTables , when I use laravel's vue component,vue also require jquery, so the DataTables can't be load correctly

In laravel SPA, When I use the DataTables which depends on jQuery, when I use laravel's vue component,vue also require jquery, so the DataTables can't be load correctly, because loading jquery twice. what should I do?

index.blade.php

<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!-- Meta, title, CSS, favicons, etc. -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>控制台 | </title>

        <!-- Bootstrap -->
        <link href="/assets/admin/gentelella/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

        <!-- ...some css... -->

        <!-- Datatables -->
        <link href="/assets/admin/gentelella/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
        <link href="/assets/admin/gentelella/vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
        <link href="/assets/admin/gentelella/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
        <link href="/assets/admin/gentelella/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
        <link href="/assets/admin/gentelella/vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">

        <!-- Custom Theme Style -->
        <link href="/assets/admin/gentelella/build/css/custom.min.css" rel="stylesheet">
    </head>

    <body class="nav-md">

        <div id="app"></div>

        <!-- load jQuery first-->
        <script src="/assets/admin/gentelella/vendors/jquery/dist/jquery.min.js"></script>
        <!-- here is some plugins, they maybe dependent on jquery,so I can't delete previous line -->
        <!-- FastClick -->
        <script src="/assets/admin/gentelella/vendors/fastclick/lib/fastclick.js"></script>
        <!-- NProgress -->
        <script src="/assets/admin/gentelella/vendors/nprogress/nprogress.js"></script>


        <!-- Datatables -->
        <script src="/assets/admin/gentelella/vendors/http://ift.tt/2nKzIVG"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
        <script src="/assets/admin/gentelella/vendors/datatables.net-scroller/js/dataTables.scroller.min.js"></script>

        <!-- main.js loaded jQuery already -->
        <script src=""></script>

        <!-- Custom Theme Scripts -->
        

    </body>
    </html>

bootstrap.js

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

window.$ = window.jQuery = require('jquery');

require('bootstrap-sass');



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

Account balance system with Stripe

For the past two days I've been trying to understand how Stripe works.. What I'm trying to build is a simple system that lets the user to add funds to his account on the site. I followed a tutorial I found on the internet that uses Laravel Cashier but as I've read on the laravel documentation if I need to perform single charges I should use directly Stripe. The thing is, there are not many tutorials on how this should be done with laravel..

Here's what I have so far:

VIEW:

    <form class="app-form" style="margin-bottom: 0px;" action="/add-funds" method="POST">
      

      <select id="funds-options" style="width: 20%; margin-bottom: 20px;" name="add-funds-select">
        <option value="30">$30</option>
        <option value="50">$50</option>
        <option value="100">$100</option>
        <option value="200">$200</option>
        <option value="300">$300</option>
        <option value="500">$500</option>
      </select>

      <p style="margin-bottom: 0px;">
        <script src="http://ift.tt/1doUtf9"></script>

        <button id="customButton">Purchase</button>

        <script>
        var handler = StripeCheckout.configure({
          key: '',
          image: 'http://ift.tt/1HOsSjY',
          locale: 'auto',
          token: function(token) {
            // You can access the token ID with `token.id`.
            // Get the token ID to your server-side code for use.
          }
        });

        document.getElementById('customButton').addEventListener('click', function(e) {
          // Open Checkout with further options:
          var userAmount = $("#funds-options").val();

          handler.open({
            name: 'Demo Site',
            description: '2 widgets',
            amount: userAmount*100
          });
          e.preventDefault();
        });

        // Close Checkout on page navigation:
        window.addEventListener('popstate', function() {
          handler.close();
        });
        </script>
      </p>
    </form>

I have this select tag where the user can select the amount he wants to add to his account. Now, this opens the widget from Stripe but as soon as I hit pay, I'm getting that info: "You did not set a valid publishable key". I tried this using the publishable key directly and I'm able to pass this but as soon as it gets into the controller it throws pretty much the same error, something like API key was not set.

I set the keys in the env file and I also reference them in the services.php..

ENV:

STRIPE_KEY=pk_test_....
STRIPE_SECRET=sk_test_...

SERVICES:

'stripe' => [
    'model' => App\User::class,
    'key' => env('STRIPE_KEY'),
    'secret' => env('STRIPE_SECRET'),
],

Anyway, even if I pass this "error" I'm still not sure if I'm doing this right.

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;

class WalletController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function index()
    {
        return view('user.wallet.index');
    }

     public function postPayWithStripe(Request $request)
     {
         return $this->chargeCustomer($request->input('add-funds-select'), $request->input('stripeToken'));
     }

     public function chargeCustomer($amount, $token)
     {
        \Stripe\Stripe::setApiKey(getenv('STRIPE_SECRET'));

         if (!$this->isStripeCustomer())
         {
             $customer = $this->createStripeCustomer($token);
         }
         else
         {
             $customer = \Stripe\Customer::retrieve(Auth::user()->stripe_id);
         }

         return $this->createStripeCharge($amount, $customer);
     }
     public function createStripeCharge($amount, $customer)
     {
         try {
             $charge = \Stripe\Charge::create(array(
                 "amount" => $amount,
                 "currency" => "brl",
                 "customer" => $customer->id,
                 "description" => "Add funds to your account"
             ));
         } catch(\Stripe\Error\Card $e) {
             return redirect()
                 ->route('index')
                 ->with('error', 'Your credit card was been declined. Please try again or contact us.');
     }

         return $this->postStoreAmount($amount);
     }

     public function createStripeCustomer($token)
     {
         \Stripe\Stripe::setApiKey(getenv('STRIPE_SECRET'));

         $customer = \Stripe\Customer::create(array(
             "description" => Auth::user()->email,
             "source" => $token
         ));

         Auth::user()->stripe_id = $customer->id;
         Auth::user()->save();

         return $customer;
     }

    /**
     * Check if the Stripe customer exists.
     *
     * @return boolean
     */
     public function isStripeCustomer()
     {
         return Auth::user() && \App\User::where('id', Auth::user()->id)->whereNotNull('stripe_id')->first();
     }

     public function postStoreAmount($amount)
     {
        $userBalance = Auth::user()->balance;
        $userBalance = $userBalance + $amount;

        Auth::user()->save();

        session()->flash('message', 'You just added funds to your account.');
        return redirect()->route('index');
     }
}

I have a field in the users table that holds the user balance.

As I mentioned, I followed a tutorial I found on the internet.. I'm not sure how this should work. Any suggestions?



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

Laravel 5.4 migrate key is too long error

when I run migrate command with laravel 5.4 I get an error "specific key was too long", I searched and found many people also face this error. The common is add Schema::defaultStringLength(191); in AppServiceProvider.php. But the doc http://ift.tt/2jcMcjh says it is for those mysql version older than 5.7.7. But my version is 5.7.14(mysql Ver 14.14 Distrib 5.7.14, for Win64 (x86_64)), and I already set mysql default charset to utf8mb4(show variables like "%char%"):

enter image description here

So I think I do not need to change anything but I still get the problem. It makes me confused. Who can help me? Thanks.



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

Does laravel not detect request locale automatically?

I am learning laravel 5.4 locale chapter. When I write code to test, I get a question. For example, I have two language directories in my resources/lang directory:

/resources
    /lang
        /en
            messages.php
        /zh-CN
            messages.php

I set default locale is zh-CN, fallback locale is en. When I set Accept-Language to zh-CN, I can get translation string in zh-CN. But when I set Accept-Language to en, I still get string in zh-CN. So laravel does not detect request locale automatically? And If my application want to show english to those Accept-Language is en, and show chinese to those Accept-Language is zh-CN, I need to do it manually, is that correct? I though laravel will detect request locale automatically.



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

Remove a package from laravel

I installed this Cartalyst Stripe package for laravel which was nothing but trouble for me.. I just couldn't get it working and now I decided to remove it completely. So, I remove the line that requires this package in composer.json. I removed the line from confing/app.php from the providers & aliases array. I also removed all references of that Cartalyst package from my code.. Somehow, after I run composer update I still get this error..

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'Cartalyst\Stripe\Laravel\StripeServiceProvider' not found


Script php artisan optimize handling the post-update-cmd event returned with error code 1

What am I missing here?



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