Member Since 2 Years Ago

Experience Points 1,290
Experience Level 1

3,710 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 2
Best Reply Awards 0
Best Reply
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement


    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement


    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

08 Feb
4 months ago
04 Feb
4 months ago

phpguru started a new conversation Something In Laravel App Monolog Is Trying To Shell_exec()

I've got some vanilla L5.6 and L5.7 apps running commands on the CLI in a secure VPC.

While combing the logs, I came across this little gem:

[2019-02-04 15:40:04] production.ERROR: shell_exec(): Unable to execute 'git branch -v --no-abbrev' {"exception":"[object] (ErrorException(code: 0): shell_exec(): Unable to execute 'git branch -v --no-abbrev' at /home/ubuntu/v1.0.29/vendor/monolog/monolog/src/Monolog/Processor/GitProcessor.php:54)

What in the world could be running this command? It's not anywhere in our code, and the stacktrace leads to the catch block of a giant try inside a fairly complicated command we run to process jobs from an SQS queue. In short, I don't have a clue what caused this error, but more importantly, what in Laravel -> Monolog is trying to call git branch on a production server.

Any clue what could be doing this? We've ruled out composer also, since no deploys happened on this server at this time.

01 Aug
10 months ago

phpguru left a reply on Reader And Writer DB Endpoints And Slave Lag

Whoa, I missed this before - from the Laravel 5.5+ docs:

The sticky Option The sticky option is an optional value that can be used to allow the immediate reading of records that have been written to the database during the current request cycle. If the sticky option is enabled and a "write" operation has been performed against the database during the current request cycle, any further "read" operations will use the "write" connection. This ensures that any data written during the request cycle can be immediately read back from the database during that same request. It is up to you to decide if this is the desired behavior for your application.

phpguru started a new conversation Reader And Writer DB Endpoints And Slave Lag

So, we have an Aurora MySQL cluster in AWS that Laravel talks to.

We had it configured to use the cluster endpoint URL for everything. In theory, SELECTs are supposed to go to the reader(s) through the cluster endpoint, and INSERT, UPDATE, DELETE are supposed to go to the writer. All is fine and dandy.

Until we run a job in PHP CLI that does a write and then immediately a read from the same table, like a $item->save()->fresh();

The issue we're having is that reloading it fails, because the SELECT that runs 2ms later is sent to the slave which is 10ms to 100ms behind, so it fails to reload correctly. Of course the default config appears to be amazing, simple and automatic for all other use cases.

So we look up in Laravel config, it's possible to specify a reader and a writer separately in the config/database.php file.

So we did that, but now for our jobs to work we have to put the writer/master endpoint into the config for both reader and writer. Now our SELECTs all go to the writer also.

Has anyone else run into this? Is there any other automatic solution to it?

I am thinking I have to define two separate connections in Laravel to the same database, one for the reader and one for the writer, and be specific with anywhere ->fresh( ) type query runs in my code to specify for the read to go to the master I just wrote on.

20 May
1 year ago

phpguru left a reply on How Can I Test A Custom Package That Use Facades?

Config works, logging (via Log::debug( ) ) doesn't. Hmm...

25 Apr
1 year ago

phpguru started a new conversation Debugging Mail::to()->send()'s Guzzle Paylod

Guzzle has a request option to debug. [1]

Mail::to()->send() uses Guzzle when using Mailgun and Sparkpost drivers.

I'm having errors with Sparkpost and need to inspect the request being sent.

Is there any way to inspect Mail send's guzzle request?

27 Feb
1 year ago

phpguru started a new conversation Has Anyone Gotten PhpStorm + Phpunit + Docker PHP Working?

I am attempting to get phpunit working in Docker PHP container with the configuration options available in PhpStorm.

Under Settings > Languages & Frameworks > PHP > PHP language level I have defined the language level to be 7.1 (the version running in Docker.)

Under Settings > Languages and Frameworks > PHP > CLI Interpreter it says app:latest I got that by clicking on the [...] button clicking + defining a new Docker server (local) picked the image name of my PHP container in the dropdown (app:latest)

The PHP version is detected here as 7.1.13 The configuration file is auto-generated to /usr/local/etc/php/php.ini which is the one from inside the Docker container.

Under Settings > Languages & Frameworks > PHP > Test Frameworks

I have the CLI Interpreter from above - it says app:latest (7.1.13) I have the Path mappings: ->/Projects/myproject I have Docker container: -v /Users/myuser/Documents/Projects/myproject:/Project/myproject

This was auto-detected, and appears to be correct.

Under Run -> Edit Configurations I defined a Phpunit Run Configuration to run my unit tests.

Ok, so when I go to run the tests...

At the top of the Run output window it says Testing started at 11:47 am... docker://app:latest//usr/local/bin/php /Projects/trinity/vendor/phpunit/phpunit/phpunit --no-configuration /Projects/trinity/tests --teamcity

This looks right, but now my test hangs for awhile, and complains

Illuminate\Database\QueryException : SQLSTATE[08006] [7] could not connect to server: 
Connection refused
Is the server running on host "db" ( and accepting TCP/IP 
connections on port 5432?

Now here's the weird thing that I don't understand.

"db" is defined in the Mac OS X host as being so I can access it with SQLPro for Postgres. Inside the docker container, it gets the NAT IP from the docker compose environment.

$ docker exec -it app /bin/bash
[email protected]:/var/www/html# ping db
PING db ( 56 data bytes

What makes no sense is that, with all of this Docker configuration defined for my CLI test, and seemingly correct, how is PhpStorm getting my Mac OS PHP configuration and DNS?

My tests do not and will not work on Mac OS X host (I have not installed the same version of PHP, nor any of the extensions) - These are all in Docker.

I can continue entering the docker container and running my tests on the command line inside the container, but I'd love to get the key commands and helpers from PhpStorm working instead, if possible.

30 Jan
1 year ago

phpguru left a reply on Working With Postgres JSONB In Laravel 5.5

whereIn() does not work that way. You're thinking of it backwards.

I don't want to provide a list of possible values, I want to provide a specific value that an array of values in JSONB node may contain.

data->info->groups returns [101, 202, 303]

I want a query where I find all the records where in_array(202, data->info->groups)

I don't think it's possible in L5.5. I don't even know if it's possible in a Postgres SQL query.

25 Jan
1 year ago

phpguru left a reply on Working With Postgres JSONB In Laravel 5.5

I saw that, but I don't want to pass the whole list of ids, eg [101,202,303] because the where clause is using the "=" operator.

I wasn't able to get anything but null when this->that->other json field is a list/array.

Trying to figure a way to query Contact::where('data->info->groups' .... contains 202)

phpguru started a new conversation Working With Postgres JSONB In Laravel 5.5

Here's our table schema

    Schema::create('contacts', function(Blueprint $table)
        $table->uuid('id')->default(\DB::raw('gen_random_uuid()'))->comment('primary key');
        $table->string('email', 100)->nullable()->comment('email address');
        $table->jsonb('data')->nullable()->comment('Any params go here');

Here's an insert statement in Tinker

Contact::create(['email'=>'[email protected]', 'data'=>'{"first_name":"Geoff","info":{"id":1234123,"groups":[101,202,303]}}'])

Here's a sample query

Contact::where('data->first_name', 'Geoff')->first()
App\Models\Contact {#890
   id: "8eeab075-57ae-4b29-8aca-df8f7c296dd4",
   rawpost_id: 0,
   vertical_id: 2,
   email: "[email protected]",
   data: "{"first_name": "Geoff", "info": {"id": 1234123, "groups": [101, 202, 303]}}",
 created_at: "2018-01-25 18:04:03",
 updated_at: "2018-01-25 18:04:03",


So far so good.

How do I find contacts that belong to group 202?

06 Dec
1 year ago

phpguru left a reply on Tinker Reload?

There's now a package (Tinx) that includes this capability:

The highlight feature of Tinx is the ability to update your Tinker session with the re() command

08 Nov
1 year ago

phpguru left a reply on Securing API Routes With Entrust Logged-in User

Well I ended up figuring some things out. I'm not sure if this is the right way to do this or not but it turns out the auth:api middleware is looking for api_token to match your logged-in user.api_token in the database. The solution came from this gem:

When making the request, you can add the api_token as a URL/Querystring parameter like so:[your 60 char key]. You can also send the key as a header (if using Postman or similar), i.e: Header: Authorization, Value: Bearer [your 60 char key].

Using this does NOT require Laravel Passport.

So now I do this in app.js:

axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
axios.defaults.headers.common['Authorization'] = 'Bearer '+window.api_token;

And in my layout partial scripts.blade.php:

    window.api_token = '<?php
        echo request()->user()->api_token;

There may be a more elegant solution, but this works for now.

phpguru started a new conversation Securing API Routes With Entrust Logged-in User

Like many others online, I'm a bit confused by middleware auth vs middleware auth:api. I have an axios request working in my Vue app by placing it in routes/web.php. I moved it to routes/api.php and now it has an api prefix, but I tested in an incognito window and the request succeeds just fine. I tried both middleware auth and middleware auth:api to secure the route, but each time it returns a 401 to the ajax request.

What do I need to do to pass my entrust-user-logged-in-status to my backend api routes to allow logged-in users access to run the API calls on my page?

06 Nov
1 year ago

phpguru left a reply on How To Make A Drop Down Component With Ajax Options

When I remove partners from the data function, and instead reference partners as a prop on the component, it yields no errors, the Ajax successfully fires, and both dropdowns remain empty of any options.

phpguru left a reply on How To Make A Drop Down Component With Ajax Options

No, I'm clearly missing the binding of the options...

In blade template I have

<div id="parametermapper">
            <partner direction="left"></partner>
            <partner direction="right"></partner>

In app.js

window.Vue = require('vue');
Vue.component('partner', require('./components/partners.js'))

in partners.js

var partnerComponent = Vue.extend({
    props: ['direction'],
    template: `
<div class="partner-component">
    <label v-bind:for="'partner_'+direction">{{ direction | capitalize }} Partner
    <select v-model="selectedPartner">
    <option v-for="partner in partners" v-bind:value="">{{ }}</option>
    </label> {{selectedPartner}}
    data: function () {
        return {
            selectedPartner: '',
            partners: [
                {id: '', name: 'Choose...'},
                {id: 1, name: 'Acme Co'},
                {id: 2, name: 'Fab Corp'}

var vm = new Vue({
    el: '#parametermapper',
    components: {
        partner: partnerComponent
    mounted() {
        axios.get('/pm/partners').then(response => console.log(response));

phpguru started a new conversation How To Make A Drop Down Component With Ajax Options

I am trying to learn Vue 2, adding some Vue to a single controller admin page inside a Laravel 5.4 Project. I hand rolled a component with a drop down menu in it and got it working with hard coded options. I put an axios call in the created() method, the Ajax fires, the option values I want are in the network inspector, no errors, but the default options never update. I guess props only flow down to the component when it’s first rendered. How is this achieved?

18 Aug
1 year ago

phpguru left a reply on L5.4 Accessors And Mutators On A Column With An Unders

Well that was easy. Thanks Tomi!

phpguru started a new conversation L5.4 Accessors And Mutators On A Column With An Unders

I wrote the following accessor and mutator for the ip_address BIGINT UNSIGNED column on my model:

 * IP Address Accessor. Returns '' from 2066563848
 * @param $integer
 * @return bool|string
public function getIpAddressAttribute($integer)
    return long2ip($integer);

 * IP Address Mutator. Stores 2066563848 from ''
 * @param $string
 * @return int
public function setIpAddressAttribute($string)
    return ip2long($string);

When I try to tinker and save it, it just returns 0.

>>> $c->ip_address = ''
=> ""
>>> $c->ip_address
=> ""

A value of 0 is getting stored to the ip_address field in the database.

What am I doing wrong?

02 Aug
1 year ago

phpguru left a reply on Laravel 5.4 Predis Config Example Not Working With .env

I debugged it to a problem in the way predis class tcpStreamInitializer receives the $parameters->port from dotEnv

In short, the $parameters->host is "redis" but the parameters->port somehow becomes "tcp://redis:6379"


After a lot of trial and error I discovered that if I change .env


and config/database.php like this:

'redis' => [

    'client' => 'predis',

    'default' => [
        'host' => env('MY_REDIS_HOST', 'redis'),
        'password' => env('MY_REDIS_PASSWORD', null),
        'port' => env('MY_REDIS_PORT', 6379),
        'database' => 0,


everything works fine. Hope this helps someone in the future.

phpguru started a new conversation Laravel 5.4 Predis Config Example Not Working With .env

I'm using Docker with container linking for the PHP server to connect to Redis via this entry in /etc/hosts:   redis 

which gets automatically injected into the app container with my docker run --link redis:redis ... command.

I followed the docs to use Predis with Laravel.

I put this in my .env


I put this in my config/database.php

'redis' => [

    'client' => 'predis',

    'default' => [
        'host' => env('REDIS_HOST', 'redis'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,


Now when I run Redis commands, it breaks with this error:

PHP warning:  stream_socket_client(): unable to connect to 
tcp:// (Connection refused) in 
/Projects/rx_api_v2/vendor/predis/predis/src/Connection/StreamConnection.php on line 127

I can't figure out how something in the docs so simple, is giving me so many issues.

24 Jul
1 year ago

phpguru left a reply on How Do You Run Laravel Tests?

Wow, that was dumb.

You have to cd into the project root.

LaravelFrameworkDir $ phpunit tests/Whatever/Test.php


cd LaravelFrameworkDir/tests

phpunit Whatever/Test.php

phpguru started a new conversation How Do You Run Laravel Tests?

I found a simple way I can make a slight improvement to Laravel codebase and wanted to submit a pull request. I wanted to also write a unit test for my contribution.

I checked out Laravel/Framework from my fork in Github and tweaked the code.

I wrote a new test (in the Database Blueprint test)

When I try to run Laravel tests to see if my code passes the test, none of the tests work.

   $ phpunit Database/DatabaseSchemaBlueprintTest.php 
PHPUnit 6.1.4 by Sebastian Bergmann and contributors.

EEEEE                                                               5 / 5 (100%)

Time: 80 ms, Memory: 8.00MB

There were 5 errors:

1) Illuminate\Tests\Database\DatabaseSchemaBlueprintTest::testToSqlRunsCommandsFromBlueprint
Error: Class 'Mockery' not found


2) Illuminate\Tests\Database\DatabaseSchemaBlueprintTest::testIndexDefaultNames
Error: Class 'Illuminate\Database\Schema\Blueprint' not found


3) Illuminate\Tests\Database\DatabaseSchemaBlueprintTest::testDropIndexDefaultNames
Error: Class 'Illuminate\Database\Schema\Blueprint' not found


4) Illuminate\Tests\Database\DatabaseSchemaBlueprintTest::testDefaultCurrentTimestamp
Error: Class 'Illuminate\Database\Schema\Blueprint' not found


5) Illuminate\Tests\Database\DatabaseSchemaBlueprintTest::testUnsignedDecimalTable
Error: Class 'Illuminate\Database\Schema\Blueprint' not found


Tests: 5, Assertions: 0, Errors: 5.

Could someone help me out? I'm kind of confused how to run tests against Laravel/Framework.

22 Apr
2 years ago

phpguru started a new conversation [PDOException] SQLSTATE[HY000] [2002] No Such File Or Directory

I've been using Docker for Windows with Laravel 5.3 + Spark for nearly a year. Now all of a sudden, something has changed in my environment and I cannot figure out what. When I try to do a migrate, I just get the error.

[email protected]:/var/www# php artisan migrate

  SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = forge and table_name =

  SQLSTATE[HY000] [2002] No such file or directory

  SQLSTATE[HY000] [2002] No such file or directory

So far, I've completely reset Docker to default settings and rebuilt all my containers, I've done a rm -rf vendor/* and reinstalled all libraries via composer install, all to no avail. I'm running out of ideas. The weirdest thing is this was all working fine yesterday and I can't think of anything that has changed on my environment.

I even tried using PDO to connect to the database via php artisan tinker and it works fine.

10 Apr
2 years ago

phpguru left a reply on Class 'Laravel\Spark\Providers\SparkServiceProvider' Not Found

It's a permissions error for us sometimes, too. This is due to the fact that the spark repo is a paid for repository and requires rights that composer doesn't handle. If you bought spark, it should be installed in the project root (by the Spark installer).

Check to see if vendor/laravel/spark exists but it's an empty folder. If so, delete it and run composer install again.

You should have this in your composer.json under the "require" node:

"laravel/spark": "*@dev",

Then under "repositories" node you have a

"url": "./spark"

This configuration allows composer to install laravel/spark from the repository url ./spark in the local project.

04 Mar
2 years ago

phpguru left a reply on Seeder Class Not Found In Laravel5 Seeding

@Ruffles solution worked for me. Thanks!

25 Feb
2 years ago

phpguru started a new conversation Where To Store Custom Spark Components?

I'm adding an "Organization" functionality onto the Spark settings page, that will work just like the teams tab. It's coming together like so:

I added this to ProjectRoot\resources\assets\js\spark-components\settings\organization.js

var base = require('settings/organization');

Vue.component('myapp-organization', {
    mixins: [base]

And this to ProjectRoot\resources\views\vendor\spark\settings\organization.blade.php to mockup the template:

<myapp-organization :user="user" inline-template>
    <!-- Organization -->

And this to ProjectRoot\resources\assets\js\spark-components\bootstrap.js to load the custom component:


Now here's the question.

I have it working currently with the component code to load from inside the /spark folder with the other spark js, at ProjectRoot\spark\resources\assets\js\settings\organization.js

module.exports = {
    props: [],
    data() { // code },
    mounted() { // code }

This is bad practice, right? I want my /spark directory void of any customzations, don't I?

Where can I put the component code inside my project?

07 Feb
2 years ago

phpguru started a new conversation Using MySQL With SSL

I'm wondering if it is possible to use Laravel 5.3 with MySQL over SSL. From what I can find online, it seems that PDO has an SSL bug[1], and Laravel requires PDO so I am concerned this will stop our app dead in the water since our security team requires to connect to MySQL securely.


24 Jan
2 years ago

phpguru started a new conversation How To Consume API With Generated Token?

I've got Laravel & Spark set up and have been working on my API that I've currently been using only with the logged-in user's session. What do I need to do, say, from a remote site or using Postman, to use the API with my user's generated token?

Specifically what I'm after is, what do I put in Postman? An X-Authenticated header? Where do I put and what do I call my API Key and Secret from the Laravel Spark settings page, to avoid refreshing my browser every minute to get a new valid web token?