Posts

Showing posts with the label Laravel 5

Creating A Custom Exception Class And Custom Handler Class In Laravel 5.3

Answer : Laravel calls the render function of App\Exceptions\Handler class. So overriding it will not work. You have to add it in App\Exceptions\Handler class only. For example: <?php namespace App\Exceptions; use Exception; use Illuminate\Auth\AuthenticationException; use App\Project\Frontend\Repo\Vehicle\EloquentVehicle; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; class Handler extends ExceptionHandler { /** * A list of the exception types that should not be reported. * * @var array */ protected $dontReport = [ \Illuminate\Auth\AuthenticationException::class, \Illuminate\Auth\Access\AuthorizationException::class, \Symfony\Component\HttpKernel\Exception\HttpException::class, \Illuminate\Database\Eloquent\ModelNotFoundException::class, \Illuminate\Session\TokenMismatchException::class, \Illuminate\Validation\ValidationException::class, ]; /** * Report or log an except...

Convert Array To Collection In Laravel

Answer : Edit; I understand this question is getting a lot of hits based on the title so the TLDR for those people is to use the collect() helper to create a Collection instance. In answer to the questioner's brief: If you have $collection = collect([ (object) [ 'website' => 'twitter', 'url' => 'twitter.com' ], (object) [ 'website' => 'google', 'url' => 'google.com' ] ]); You then have your array wrapped in an instance of the Collection class. That means it does not behave like a typical array (- it will be array-like, but don't treat it like it is one -) until you call all() or toArray() on it. To remove any added indices you need to use values() . $sorted = $collection->sortBy('website'); $sorted->values()->all(); The expected output: [ {#769 +"website": "google", +"url": "googl...

Create Plan On Stripe Through Laravel

Answer : laravel/cashier just doesn't have this functionality baked in. You aren't out of luck though as it is easy to just use Stripe's API which should be downloaded as a dependency in your vendor folder. If not you can just download it with composer. composer require stripe/stripe-php 2.* You can use it with use \Stripe\Plan; Plan::create(array( "amount" => 2000, "interval" => "month", "name" => "Amazing Gold Plan", "currency" => "usd", "id" => "gold") ); You can read more here - https://stripe.com/docs/api#create_plan Thanks so much. I learned lots of things by this thread. But for latest cashier and stripe-php versions few thing need to be changed. My cashier version is 7.0 ( "laravel/cashier": "~7.0" ) and it automatically installs stripe-php 5 . But some parameters has changed from stripe api. So this code will be working, \Strip...

Can Anyone Explain Laravel 5.2 Multi Auth With Example

Answer : After lots of digging and lots of questions & answers I have finally managed to work Laravel 5.2 Multi Auth with two table, So I'm writing Answer of my own Question. How to implement Multi Auth in Larvel 5.2 As Mentioned above. Two table admin and users Laravel 5.2 has a new artisan command. php artisan make:auth it will generate basic login/register route , view and controller for user table. Make a admin table as users table for simplicity. Controller For Admin app/Http/Controllers/AdminAuth/AuthController app/Http/Controllers/AdminAuth/PasswordController (note: I just copied these files from app/Http/Controllers/Auth/AuthController here) config/auth.php //Authenticating guards 'guards' => [ 'user' =>[ 'driver' => 'session', 'provider' => 'user', ], 'admin' => [ 'driver' => 'session', 'pro...

Composer Dump-autoload Or Update Results In Fatal Error On Laravel 5.5

Answer : I just found a solution to this problem. Here it is for those who have the same problem. I have had to delete the directory kylekatarnls located inside my vendor directory then run composer update --prefer-source and after that composer dump-autoload . Now all is working just fine. It seems like you're using Composer v2. If so, read on... Composer v2 adds some new functions to their Plugin interface (namely deactivate() and uninstall() ) However kylekatarnls/update-helper < v1.2.1 is implementing said interface but does not implement the new functions . So to fix, you'll need to update kylekatarnls/update-helper to the latest (v1.2.1 at time of writing), which contains a fix (implements the missing methods): composer update kylekatarnls/update-helper I remove the vendor directory and the composer.lock file. After execute composer install and all works well.