Member Since 2 Years Ago

Experience Points 16,160
Experience Level 4

3,840 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 148
Best Reply Awards 1
Best Reply
  • 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.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    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.

16 Jun
1 month ago

Breki started a new conversation (PHPStorm) PHPUnit Tests Towards Dockerized Database Woes

First a quick note on my setup:

I have a dev environment and a production environment, both running more or less the same code with APP_ENV and APP_URL being the only real differentiator - everything else is handled by internal logic. The site itself is powered by docker-compose, where I've got six different containers running various jobs (php-fpm, Horizon, redis, nginx, etc...). They talk to each other internally using their logical hostnames, so php-fpm only needs to make a call to the hostname postgres, and it is mapped to the right container. For that reason, my app.php file only contains pointers to these dynamic hostnames. One great benefit of this is that I can be very restrictive as to what is available "from outside". At the moment, for example, I'm only exposing ports 80, 443, and 6001 (websockets).

Now, the issue comes when I am doing development on this platform. Since PHPStorm isn't inside the docker container, it cannot see the database. Similarly, if I try to User::first() outside of the website context, it fails. I've somewhat resolved this by setting up a Docker container called workspace where I can run phpunit, php artisan tinker etc, as this container can see the database. But I can't seem to set up Test Driven Development workflows in PHPstorm...

Now, I've gathered that I need to be running "remote PHP" towards the workspace container, but every time I try to run PHPUnit from PHPStorm, it errors out and says:

    Testing started at 18:08 ...
    [docker://backend_workspace:latest/]:php /opt/.phpstorm_helpers/phpunit.php --configuration /var/www/phpunit.xml.dist

    Process finished with exit code 1
    Cannot find PHPUnit in include path (.:/usr/share/php)

.... Which is confusing, since I have no idea where it's taking the /opt/.phpstorm_helpers/phpunit.php pathname, and PHPUnit is definitely in the path of the workspace container.

Any thoughts?

25 Mar
3 months ago

Breki started a new conversation Blade Templating Woes

I've got a design heavily based on components which are passed variables. However, some of these variables are optional, so my blade templates have a whole lot of @if(!empty($title)) in them.

Now, before I go writing my own blade tag for this kind of thing, is there something in the language that would cover this kind of scenario in a better-looking way? I'm looking for something like an @ifexists($title) or @ifset($title) kind of a thing.

12 Nov
8 months ago

Breki left a reply on CORS Issues In VUE On Local Machine

Laravel uses a CSRF Token to ensure that cross-site API calls are forbidden. By default, this is set up in your app.js and bootstrap.js files. This service that you are trying to connect to is complaining that the CSRF Token added to the request is not a permitted header when communicating with them.

My suggestion would be to encapsulate this particular method a little bit more and import cryptoCompareAxios from 'axios' and then use that instead of the axios in the third line of your method.

Breki started a new conversation Dockerizing The Recurring Jobs Runtime

Quick question. I've been thinking of setting up a Docker container containing a slimmed down version of my existing Laravel app, but just the backend. The idea here is that it would be responsible for the recurring jobs, including backups, generating aggregations in the database, and so on. All it would need is access to the filesystem and database. Am I right in assuming that the app, config and vendor folders are the only things I need to concern myself with?

Breki left a reply on How To Change Models Directory Without Any Problem?

IDEs like PHPStorm allow you to refactor a namespace and it will automatically update all mentions of that class to the new namespace. It's mostly consistent and hasn't ever caused me any major concerns.

Now, for the future, instead of having to type php artisan make:model Models\System\LoginLogBackups or similar, here's a fairly quick thing you can do to change the base namespace for your models:

namespace App\Console\Commands;
use Illuminate\Foundation\Console\ModelMakeCommand as Command;
class ModelMakeCommand extends Command
    **protected function getDefaultNamespace($rootNamespace)
        return "{$rootNamespace}\Models";

First, add that file to your app\Console\Commands. This will override the default namespace hook.

And to make it stick, add this to your app\Providers:

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Console\Commands\ModelMakeCommand;
class AppServiceProvider extends ServiceProvider
    public function register()
        **$this->app->extend('command.model.make', function ($command, $app) {
            return new ModelMakeCommand($app['files']);**

Breki left a reply on Tighter Coupling Between Laravel (PHP) And Vue (JS)

Sure, anything I build for this would by definition be an optional package; nothing that I would suggest merging into Laravel or Vue. :) I'm mostly just thinking of adding conveniences where the Laravel <-> Vue communication is being made more difficult than it has to be.

Breki left a reply on Stripe Webhooks And Auth

Yeah, I'd suggest the Cashier package as well. You don't have to use all of it, but its webhook management is great. Basically you just add a row to your routes that looks like Route::stripeWebhooks('webhook-from-stripe'); or similar. Then you can have a config object that looks like:

return [
    'signing_secret' => $signSecret,
    'model'          => App\Models\System\StripeWebhookCall::class,
    'jobs' => [
        // HandleAccountEvent
        'account.application.authorized'       => App\Jobs\StripeWebhooks\HandleAccountEvent::class,
        'account.updated'                      => App\Jobs\StripeWebhooks\HandleAccountEvent::class,
        // HandleBalanceEvent
        'balance_available'                    => App\Jobs\StripeWebhooks\HandleBalanceEvent::class,
        // HandleChargeableEvent
        'source_chargeable'                    => App\Jobs\StripeWebhooks\HandleChargeableSource::class,

And then your actual jobs would be something like:

    public function handle ()
        switch ($this->type) {
            case 'customer.source.created':
            case 'customer.updated':
            case 'customer.deleted':
            case 'customer.created':
     * @throws \App\Exceptions\Webhooks\WebhookDetailNotFound
    protected function customerSourceCreated ()
        if (CustomerSource::addSource($this->payload) === true) {
            Log::info('[' . $this->webhookCall->id . '] New funding source added for ' . $this->user->name . '.');
        } else {
            Log::error($this->id . 'Source could not be added to customer.');

If you do decide to go this route, here's a tip that I learned the hard way... Build a StripeWebhookHandler class and have other classes that extend it (one for accounts, one for customers, one for subscriptions, one for billing, etc), because you're going to want to split these things up but still allow them to share some features, like the following __construct method:

     * StripeHandler constructor.
     * @param \App\Models\System\StripeWebhookCall $stripeWebhookCall
    public function __construct (StripeWebhookCall $stripeWebhookCall)
        $this->webhookCall = $stripeWebhookCall;
        $this->payload = array_dot($this->webhookCall->payload);
        $this->type = $this->payload['type'];
        $this->queue = 'StripeQueue';

I've been working with Laravel/Stripe integrations for the past year, so feel free to ask me if you have any questions! :)

Breki started a new conversation Tighter Coupling Between Laravel (PHP) And Vue (JS)

I've been building a fairly large project for the past year, starting as almost purely PHP-based backend coding, moving to Blade-based frontend work, and now moving to Vue. I've been migrating a lot of my Blade Views to Vue Single File Components...

During all of this, one of my major annoyances has been with how much work I'm having to repeat just to get the things that are already working in PHP => Blade to work in Vue... So I've been thinking - how much work has been done in developing tools and systems to better couple things from Laravel into Vue? There are several things that I can imagine being extremely useful but haven't been built yet (or which I haven't found, at least...) So I'm asking - does any of this exist today, and (if not) which of these things are most interesting to people out there to use once I sit down and start writing these extensions myself?

  • A way for components to "natively" export things directly to Vue.

... say something like return view('')->withVue(['articles' => $articles]);, which would be able to pass 'articles' in as a Vue component prop...

  • A way for Vue-Router to understand Laravel's route definitions.

... maybe adding notation/syntax to Laravel's route files so that Vue-Router doesn't need any configuration files of its own...

  • Eloquent in Vue

... This is a big one, of course, but shouldn't be too difficult if one is okay with this being done server-side in a separate process. Would reduce the need for APIs and Axios and VueX for so many of the 'smaller' things we do.

  • Javascript (Node) jobs in Laravel's job worker

... Again, not too difficult if you're okay with something like $schedule->exec('node /var/www/scripts/maint/backup.js')->daily();, but a tighter integration should be possible...

... These are just a handful of examples that I've been thinking about of late, but something that I believe would come in very handy for people wanting to implement Vue (or expand Vue's presence on their site) but who don't have much Javascript experience... What do you think?

24 Jan
1 year ago

Breki started a new conversation More About Redis

Hi, I've got two quick questions relating to Redis, when used as a Cache and when used as a Queue manager. I'll start with the easy one, regarding Cache.

#1 - The Easy One.

One of the things that I was very interested in was the ability to add data to the cache using tags. One of the things that I need to do is to parse a lot of information, and sometimes that information comes from various sources, so I've been using an mySQL table with columns for 'provider', 'queue' and 'data' - with 'data' being a JSON object, essentially. But if I would be able to use the Cache for this, then 'provider' and 'queue' could just be tags instead.

However, I can't for the life of me figure out the best way to "pop the stack" so to speak. If I've got 10 items in the Cache, and three of them have the tags foo and bar, what's the easiest way for me to get one item from the Cache while simultaneously removing it from the cache? Or am I thinking of this too much like a messaging queue?

#2 - The Harder One.

In the management of recurring tasks, you can Redis::Throttle() a job, banning it from running more than X times in Y minutes/hours. However, I can't seem to find any information about how to do things like:

  • Reset that timer.
  • See how many times it has run in the past Y minutes/hours.
  • Add Z permitted calls on a one-time-only basis.

The documentation doesn't help me much in this, and reading the code doesn't reveal anything either. Is this feature too recent to feature these kinds of extra bells and whistles?

22 Jan
1 year ago

Breki left a reply on Validation If Blocks.

There's really no problem here, this is fairly common in many applications and often called "guard statements". It would be different if you just had a series of IF-statements that were used to define what the end result of your method would be, but if you're just using them to fail early I can't see the problem.

That said, I'd definitely agree with previous posters that exceptions are the way to go here. Also, I'd definitely suggest you break things down a bit if possible, so that there's no one "validation" function that has all of this in it. So it might be something like:

public function validateModelDetails()

And then each of those functions would be something like:

protected function validateDimensions()
    if ($this->length >= 141l) {
        $this->length = null;
        throw new Exception('Length invalid.');

    if ($this->length === null) {
        throw new Exception('Length cannot be null.');


Breki left a reply on Am I On Good Way Or I Should Refactor ?

I would definitely refactor. Every one of these blocks:

        if($profile->show_relationship_status == 1){
            $relationship_status = User::find($id)->relationship()->first();
        } else {
            $relationship_status = null;

Contains a whole lot of extra code that you don't need. You could pair this entire block down to just:

$relationship_status = User::find($id)->relationship()->first() ?? null;

This brings your entire first block of code down to a dozen lines. After that, you could simplify it even further by making your array-creation look like this, so you don't need all that temporary variable creation:

$info = [
    'physical_gender' => find($id)->physicalGender()->first() ?? null,
    'mental_gender' => find($id)->mentalGender()->first() ?? null,
    'sexuality' => find($id)->sexuality()->first() ?? null,
    'smoking' => find($id)->smoking()->first() ?? null,
    'alcohol' => find($id)->alcohol()->first() ?? null,
    'language_i_know' => find($id)->languages()->select('name','level')->get() ?? null,
    'language_i_want_to_learn' => find($id)->unknownLanguages()->get() ?? null,
    'relationship_status' => find($id)->relationship()->first() ?? null,
    'children_status' => find($id)->children()->first() ?? null,
    'search_status' => find($id)->search()->first() ?? null,
    'religion' => find($id)->religion()->first() ?? null,
    'country' => find($id)->countries()->first() ?? null,
    'city' => find($id)->city()->first() ?? null,

Also, that view of yours has way too much PHP in it. It's a Blade view, so why not use the native Blade syntax for most of the things you're doing? The IF-statements, the echo-statements and the ucfirst, all are more easily available through Blade or Laravel Helpers like title_case and so on.

18 Jan
1 year ago

Breki left a reply on Filesystem Fails On Absolute Path. FILE DOES NOT EXIST.

Are you sure the file exists? That $image does not look like an URL that would validate.

Breki left a reply on Queue Worker Via Schedule Command Not Working

Just out of curiosity, what happens when you php artisan queue:work ?

Breki left a reply on Ignore Facebook Scrape

I can give you a hint in the right direction. ;)

Take the controller which contains your view and add use Illuminate\Http\Request; to it. Then go to the function which calls your view and add Request $request to the list of arguments to that view. Then put dd($request) as the first thing in that function and reload it. I'm sure you'll find something there that you can filter on. Maybe the user agent string? Maybe the referrer?

Breki left a reply on Correct Way Of Identifying Users Tagged In A Post

Without answering the first part of your question, here's my suggestion for your "second". You could implement a system where the post body is scanned every time a post is saved and a new list of tags is identified. Say the format is something like $post->taggedUsers = [5,11,65,104,525]

This list is then compared to the previous list through a whereNotIn(), which in one direction will allow you to see which users were tagged but which are no longer tagged. In the other direction, it will allow you to see the users that were not tagged but which are now tagged.

(Note: Remember to be careful here, you don't want it to keep the tags of users who delete their accounts etc).

Breki left a reply on 2018- Best Hosting (subjective)

Digital Ocean is and remains my absolute favorite, withuot a doubt. One of the most flexible and reliable webhosts I've ever worked with.

Breki left a reply on Laravel + Vuejs Authentication

What is it you want VueJS to be doing in this scenario? Is it offering you the login page through a Vue Component, or what?

Breki started a new conversation Test Against Value In Array/JSON

I've got a database table called scrapeobjects which I use as temporary storage for a number of scraper and parser jobs. The structure is basically an id, a category text field, a type text field and a data JSON field (plus the created/updated_at fields, of course). Reading and writing to this from Eloquent has never been a problem and I've been able to use the flexibility of the JSON field to my advantage in many situations.

However, I've recently come across a situation where I need to ensure that an item in this table isn't already in the table, based on a key/value combination in the JSON field. I consider myself fairly good at Eloquent and figured it should be fairly simple, but no matter what I tried, it doesn't want to work.

Say we've just scraped the following data: {"id": 424, "caption": "European Championships France 2016", "league": "EC", "year": "2016", "currentMatchday": 3, "numberOfMatchdays": 7, "numberOfTeams": 24, "numberOfGames": 38, "lastUpdated": "2016-06-22T04:34:39Z"}. Now I want to send it to the parser, but due to the nature of the data coming into the system, we cannot be sure that another scraper hasn't added it already. So we wan to make sure that there's no data object with the same caption, for example.

So, how would I use Eloquent to use the model ScrapeObject, the column data and the field caption in a search? It's easy to ScrapeObject::first()->data->caption but I can't find a way to query the 'caption' field.

In the interrim, I'm using a primitive deserialization through in_array($this->option('caption'), ScrapeObject::pluck('data')->flatten()->unique()->toArray(), true)) ... which just upsets my feeling for good code standards, to be honest :D

15 Jan
1 year ago

Breki started a new conversation Redis::throttle

So there's this API that I'm pulling data from that is quite restrictive with its hits per time period settings, so I was very glad to find the Redis::throttle command. However, I've got one slight issue with it, too.

How do I find out how many hits are available in the current time period? Say I've got something like:

    function () {
    }, function () {
        Log::warning('Could not establish throttle in port call operation.');

This allows the SomeJobThatNeedsDoing to run five thousand times every day, which is fortunate, because I have it scheduled to run five times a minute - meaning it'll run into the limit by early evening.. But how do I see how far away from its limit it is at the moment?

22 Nov
1 year ago

Breki left a reply on Avoiding Dynamic Calls

Right. It seems you misunderstood my question, though. I wasn't asking specifically about making a column in a form unique. The question might as well have been:

I'm scraping a newspaper website and making a word usage frequency counter, so should I be doing if (WordList::where('word', $word)->count() === 0) { addWord($word); } or [... etc].

The question is implicit in the title of the post. Does Laravel recommend dynamic calls, Posts::where('answered', false)->orderBy('updated_at')->first(), or does it recommend static calls, i.e. $posts = new Posts(); $posts->where('answered', false)->orderBy('updated_at')->first() [... etc].

Thanks! :)

21 Nov
1 year ago

Breki started a new conversation Avoiding Dynamic Calls

Quick question!

Assume I've got a model containg users, which includes usernames, last login time, account creation, e-mails, etc, etc. Let's call the model Users. Now; in many places in the code, I'll be wanting to make checks against this table to see if we're trying to assign an e-mail address to an user when that e-mail address already exists on another user or something like that.

So far, I've been doing this with dynamic calls, things like if (Users::where('email', $this->formResults->email)->count() > 0), (after casting all to lowercase and trimming/validating, of course) but I'm beginning to wonder if Eloquent models should be used in this way or not.

I've seen the alternate usage of:

$userList = new User();
$uCount = $userList->where('email', $this->formResults->email)->count();
if ($uCount > 0) {

It's more wordy, for sure, but I'm wondering which is the recommended method?

28 Aug
1 year ago

Breki left a reply on Seeder That Needs To Post JSON

Haven't tried this myself, but I assume you should be able to define the field type as 'array' (using protected $casts ) for that database column, and then save an array into it - it should convert it to a JSON object

27 Jul
1 year ago

Breki left a reply on Using Carbon Inside Of An Eloquent Scope

That's the issue, right there, the "SomeOtherCondition". Because I'm not really concerned about SubDays(5), I'm concerned about SubMinutes('Frequency'), which obviously doesn't work.

Again, I have the last time the job ran in one column, and I have the frequency that it should run in another column. I want my scope to query based on the LastCompleted after it has been modified by the Frequency - compared to the present time.

Imagine it like this:

$LastCompleted = '2017-06-27 19:30:00';  
$Frequency = 50; // minutes
if (Carbon::parse($LastCompleted)->addMinutes($Frequency) > Carbon::now()->utc) {
  echo 'We are overdue!';

And then imagine doing _that_ inside of an Eloquent "scope" query. :-)
26 Jul
1 year ago

Breki started a new conversation Using Carbon Inside Of An Eloquent Scope

I've got a database table for recurring tasks which contains (amongst others) a LastCompleted and a Frequency column, where one can easily see how Carbon::parse($Schedule->LastCompleted)->addMinutes($Schedule->Frequency) would give us the time that that particular event is supposed to run again.

However, I'm trying to write a scopeOverdue inside of that model, and I can't figure out how best to write it. How do I access two fields from the same model and apply some Carbon-logic to them and then only return the fields that match?

13 Jul
2 years ago

Breki started a new conversation Touching Scopes?

Been having a tricky issue that I'm not really sure how to handle. I've got a number of entries in a database table that, while they do have an unique id, are basically defined by a combination of two separate ENUM fields. To make things simple, we can imagine that one ENUM contains the alternatives "Watch", "Play" and "Discuss", and the other ENUM contains Baseball, Football, and Tennis, leading to a total combination count of nine different alternatives - each of which has its own row. I then have a fourth column called LastCompleted, which is basically there to indicate when the last time the operation that matches those two criteria was completed. There are a couple of other columns, but none of these are important in the grand scheme of things as they only contain metadata used by other sources.

Now; to make things easy for myself, I set up a couple of scopes in the model for this table, which look like:

public function scopePlay($query)
    return $query->where('Task', 'Play');

public function scopeTennis($query)
    return $query->where('Activity', 'Tennis');

Still simple enough, right? I'm able to select a unique row from the table with a simple $NextActivity = ActivityList::Watch()->Baseball(); to get my hands on that particular row.

The problem I'm having, however, is that this is not a database table that needs any kind of CREATED_AT, UPDATED_AT or anything like that, so I have public $timestamps = false; in the class definition, but I need it to be aware of LastCompleted, so I set it up with public $touches = 'LastCompleted'; Perhaps naively, I expected that this would mean that I could just ActivityList::Watch()->Baseball()->touch(), but that gives me the error message that touch doesn't exist there. I'm stuck with ActivityList::Watch()->Baseball()->update(['LastModified' => Carbon::now()]); which, while it absolutely works, doesn't have the same kind of deeper integration that I'm looking for.

So ... what am I missing here? What do I need to do in order for me to just be able to touch the table based on these two scopes?