Repox

Repox

Member Since 3 Years Ago

Experience Points 14,900
Experience Level 3

100 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 160
Lessons
Completed
Best Reply Awards 4
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

09 Nov
2 years ago

Repox left a reply on How To Print Blade View Contents To PDF File?

https://packagist.org/packages/dompdf/dompdf - Cashier is using this library to produce PDF invoices.

08 Nov
2 years ago

Repox left a reply on Can't Seem To Get Redirect Working

A redirect needs to be returned.

return redirect("/doc/$arrDoc");

Repox left a reply on Understanding URLs And Mage Links

@bobbybouwmann

Although your answer is correct, it doesn't explain why it's correct.

Well, you explained the problem, I just gave an alternative solution.

@fsdolphin

Both examples worked, now the question is, is there any benefit when using one over the other?

I guess that depends.

Using the / will always point to the root of the URI, meaning you can't work with the application in subdirectories. Say your domain is example.com and you want to run your app inside a subfolder (like example.com/beta), you have to do /beta/images/my-image.png to make it work. It's going to be a hoot trying to fix that when moving the application up a folder.

Using url() you'll have the benefit of combining Laravels features for generating URL's based on qualified guesses or the configuration you set, which makes it trivial to move the application to whatever directory you want if you need to.

Personally, I prefer url().

Repox left a reply on Understanding URLs And Mage Links

Or:

<img src="{{ url('images/my-image.png') }}" alt="">

Repox left a reply on Save Multiple Records

This would be pure guessing, but having a poll_id would make me assume that you also have a Poll model? If so, something like this:

$poll = Poll::find($this->id);
foreach($request->options as $option) {
    $poll->options()->save(Option::create($option));
}
04 Oct
2 years ago

Repox left a reply on How To Pass Directory Name In URL

When going through directories when returning a view, you use . instead of /.

That means you need to do it like this:

return view('business.pages.dashboard');

Additionally, you would also have to correct your route to match the correct URI:

I have created business directory in /views. URL: http://localhost/laraveldemo/blog/public/business/dashboard Route:

Route::get('business/dashboard',['as' => 'dashboard', 'uses' => '[email protected]']);

I'm unsure how the router responds to laraveldemo/blog/public/ as a part of the URL, but the basic part is as stated.

03 Oct
2 years ago

Repox left a reply on Configure Nginx For Laravel On OSX (MAC)

I know this doesn't solve your actual question, but have you considered trying out Vagrant with VirtualBox?

Spice it up with Vaprobash for your Vagrantfiles and you have multiple virtual development environments with Nginx, PHP and whatever you need in a few minutes.

29 Sep
2 years ago

Repox left a reply on Finding A Proper Cashier Workflow?

@martinbean I'm not questioning your understanding of either Stripe nor Cashier... my god, why am I even trying...

I asked for help with insights on a workflow with Cashier - that's it!

So in the simplest terms I can possibly manage: either write the logic to handle the logic and edge cases of swapping users between plans yourself, or use Spark which has this already done for you.

You know what - you tried your best. I actually asked for input for :

either write the logic to handle the logic and edge cases of swapping users between plans yourself,

And you keep rambling on about:

or use Spark which has this already done for you.

I'd effing love input on:

either write the logic to handle the logic and edge cases of swapping users between plans yourself,

and I'm not interested in:

or use Spark which has this already done for you.

So if you can't provide any meaningful insights, input or ideas to a meaningful way of:

either write the logic to handle the logic and edge cases of swapping users between plans yourself,

then I'm not interested in your input.

Repox left a reply on Finding A Proper Cashier Workflow?

@kfirba :-/

Cashier, as you know, is merely a wrapper around Stripe's SDK. Your issue here is not with Stripe's SDK or Cashier but in business logic.

I know. I stated that multiple times, so maybe try and explain that to him instead.

The solution you are looking for is probably creating a SubscriptionsController and have the methods on that controller respond to the possible actions (according to the RESTful methods).

Thank you for the input, but it's not what I'm looking for.

The issue, basically, is that I don't see an elegant way of dividing the responsibilities of the Cashier methods.

As an example, swapping a subscription is pretty easy:

$request->user()->subscription('current_plan')->swap($request->get('new_plan'));

That line by itself isn't complicated. Now, to actually do the swapping I also need to know what I'm swapping from :

$subscription = $request->user()->subscriptions()->first();
$request->user()->subscription($subscription->name)->swap($request->get('new_plan')); 

Alright, easy peasy. But I also need to know if the user actually has a subscription - if not, the code above will fail.

if($subscription = $request->user()->subscriptions()->first()) {
    $request->user()->subscription($subscription->name)->swap($request->get('new_plan')); 
}

Alright, cool - we know verify that a user is subscribed to a plan that we'd like to swap. But if the user doesn't have a subscription, then I need to create one:

if($subscription = $request->user()->subscriptions()->first()) {
    $request->user()->subscription($subscription->name)->swap($request->get('new_plan')); 
} else {
    $request->user()->newSubscription('main', $request->get('plan'))->withCoupon($request->get('couponCode', null))->create();
}

Alrighty!

But that only works if I already have a card registered, otherwise I have to send some information and the Stripe credit card token:

if($subscription = $request->user()->subscriptions()->first()) {
    $request->user()->subscription($subscription->name)->swap($request->get('new_plan')); 
} else {
    if($request->user()->hasStripeId()) {
        $request->user()->newSubscription('main', $request->get('plan'))->withCoupon($request->get('couponCode', null))->create();
    } else {
        $request->user()->newSubscription('main', $request->get('plan'))->withCoupon($request->get('couponCode', null))->create($request->get('stripeToken'), ['email' => $request->user()->email, 'description' => $request->user()->name]);
}

Alright, now were getting somewhere. It's not pretty, but hey - it works!

But now I also have to consider cancels, grace periods and so on. This will eventually clutter a single controller too much - and I bet someone already worked with Cashier and implemented a workflow that will clean the controllers up a bit.

That's just the experience I'd like to hear from.

Repox left a reply on Finding A Proper Cashier Workflow?

@martinbean I'm not misunderstanding anything, you are.

I'm merely asking for someone to provide some experience with the workflow of Cashier. I am fully aware that Cashier is wrapping the Stripe SDK.

What I'm saying is that I'm dissatisfied with my current flow and I'm having a hard time getting my head around an elegant solution and I'd appreciate some input from someone who has more experience with implementing Cashier.

What I'm not saying is that I'm having problems with Cashier. Your suggestion to buy myself out of a non existing issue is completely out of scope.

Repox left a reply on Laravel5/socialite GetAvatar()

What does your User model look like?

Repox left a reply on Log Rotation In Laravel 4.1.*

You could also take a look at the log rotation service on your server. Here's a sample config: https://gist.github.com/Repox/e6cbee28c4310c3885e9

Repox left a reply on Laravel Updation

There's a dedicated upgrade guide available: https://laravel.com/docs/5.3/upgrade

Repox left a reply on Finding A Proper Cashier Workflow?

@martinbean I know it probably would solve someone's problem, but buying myself into a solution doesn't give me any learning. That's like asking people to buy professionals to solve their issues, when they are trying to learn how to do it themselves.

If Cashier is causing me pain to solve a subscription implementation, I'd might as well go with the official Stripe PHP library and not bother with Cashier.

28 Sep
2 years ago

Repox left a reply on Form Validation Bag Is Empty , Laravel 5.3

You need to pull out the messages inside the message bag with the all() method:

    @if (count($errors) > 0)
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

Repox left a reply on Finding A Proper Cashier Workflow?

@martinbean Even though I appreciate the referral, it doesn't really solve my problem, but it of course will offhand me some money (which probably would be nice for someone).

In my opinion, it should be fairly simple and reasonable to use something like Cashier, especially when it's an official Laraval Package.

Repox left a reply on Writing A URL In If Statement

You have a double single quote in the end of this conditional:

  <td>@if($device->name ==='SAMRAT'')

Repox left a reply on Multiple Registration Form Requests

For transparency, I would probably prefer separate views and controllers, depending on the role they will have.

That said, I rarely do frontend work, so a dynamic form could be a good option, but personally I'd have different controllers and validators for each role in your case.

Repox started a new conversation Finding A Proper Cashier Workflow?

I'm currently messing around with adding payments to my application and I have to say that I find it somewhat difficult to find a proper workflow and avoiding caveats and gotchas.

With somewhat ease, after getting the Stripe payment form up and running, a simple subscription can be made:

    public function updateSubsription(Request $request)
    {
        $this->validate($request, [
            'stripeToken' => 'required',
            'plan' => 'required|in:starter,business',
        ]);

        $request->user()->newSubscription('main',  $request->get('plan'))->create($request->get('stripeToken'), [
                'description' => $request->user()->name,
                'email' => $request->user()->email,
            ]);
        }

        return redirect(route('app::plans'));
    }

Now, there's a lot of things that can happen here; the customer wants to upgrade, downgrade, cancel, resume a cancelled subscription or update his credit card.

Trying to accommodate the first three, apparently requires a lot of conditionals. My current solution looks like so:

    public function updatePlan(Request $request)
    {

        $this->validate($request, [
            'plan' => 'required|in:free,starter,business,professional',
            'couponCode' => 'string',
        ],
            [
                'plan.required' => 'You need to select a plan.',
                'plan.in' => 'You need to select a valid plan.',

            ]);


        if ($subscription = $request->user()->subscriptions()->first()) {
            if ($request->get('plan') == "free") {
                $request->user()->subscription($subscription->name)->cancel();
            } else {
                $request->user()->subscription($subscription->name)->swap($request->get('plan'));
            }
        } else {
            $request->user()->newSubscription('main',
                $request->get('plan'))->withCoupon($request->get('couponCode', null))->create();
        }
    }

I don't like that solution (looks messy) and I haven't considered the resuming of a subscription yet.

Has someone more experience with Cashier to give me a better workflow?

23 Jun
3 years ago

Repox left a reply on Adding API Routes To My Laravel Application?

That seems like a possible solution to verifying the API key at least. Do you have an idea to prettying up the response setup?

Repox started a new conversation Adding API Routes To My Laravel Application?

So, basically I'm pretty far with my small web application and now I want to add a few simple API endpoints that returns some JSON responses.

I think my current solution is bad because I feel I'm forcing JSON responses (especially when validating requests) and my way of checking for the API key (and validating it) it centralized into the controller (and is forcing me to do it again in other controllers). I should probably move the API key check into some middleware, but then I have to somehow make the $application variable accessible to the controllers.

Anyway, I'd appreciate some input on my solution - the following is how my small and simple API is set up now.

Route

Route::group(['prefix' => 'api/v1', 'middleware' => ['api']], function() {
    Route::get('/', 'Api\v1\[email protected]');
    Route::post('/survey', 'Api\v1\[email protected]');
});

SurveyController

<?php

namespace App\Http\Controllers\Api\v1;

use App\Apikey;
use App\Jobs\SendRequestEmail;
use App\Score;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Support\Facades\Validator;

class SurveyController extends Controller
{
    private $application;

    public function __construct(Request $request)
    {
        if (!$apikey = $request->header('X-api-key', false)) {

            if (!$apikey = $request->get('api_key', false)) {
                abort(401, 'API key is not provided', ['Content-Type' => 'application/json']);
            }
        }

        if (!$apikey = Apikey::where('key', $apikey)->where('active', true)->first()) {
            abort(403, 'API key cannot be found or is no longer active', ['Content-Type' => 'application/json']);
        }

        $this->application = $apikey->application;
    }

    public function index(Request $request)
    {
        return response()->json(['status' => 'ok']);
    }

    public function newSurvey(Request $request)
    {

        $validator = Validator::make($request->all(), [
            'email' => 'required|email',
            'name' => 'string',
        ]);

        if ($validator->fails()) {
            return response()->json($validator->errors(), 422);
        }

        $score = new Score($request->all());

        $this->application->scores()->save($score);

        $job = (new SendRequestEmail($this->application, $score));
        $this->dispatch($job);

        return response(null, 201);

    }
}