Member Since 2 Years Ago

Experience Points 28,530
Lessons Completed 277
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.

13 Jul
6 months ago

natcave started a new conversation How Can Mix Use Different Production Environment Variables?

I set up 2 simple pusher channel apps, 1 for dev and 1 for production.





import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: true

This worked fine in dev, but when I compile and push up to production it keeps the dev .env file variable values.

Can someone tell me how to get mix to keep using the dev .env file variable values in dev but then use production .env file variable values in production?

I have a hunch the solution lies with npm run production and npm run dev and I may need to add some code to webpack.mix.js , but I'm not sure. I'm hoping someone ran into this issue already and can let me know.


06 Jul
6 months ago

natcave started a new conversation Is There A Better Way To Reference The Mailable Class Name When MessageSending Event Fires?

I'm building an email log table. One of the fields will store the name of the mailable class, for example ""App\Mail\Welcome". The idea is I want to be able to track how many times an email was sent so that automating emails will prevent sending the same email type more than once.

The way I did it was to store the mailable class name in the build function like so:


class Welcome extends Mailable

public function build()
    $mailable = get_class($this);
    return $this->markdown('emails.welcome')->subject("Welcome.")

Then, in Listeners\LogSendingMessage.php

// Check for Mailable
if (isset($event->data['mailable'])) {
    Log::info("Mailable: " . $event->data['mailable']);

This works, however I would need to add $mailable = get_class($this); to every Mailable. Is there a way of accessing the Mailable class name directly from the event?

Thanks in advance!

05 Feb
11 months ago

natcave left a reply on Calling A Model Relationship Refreshes The Csrf_token.

Found the solution. I'm not exactly sure why Eloquent was causing the problem but the real problem going on in the background was I was saving a model instance to the web session. The data was taking up a lot of space in the session files. I assume at some point it breaks the session and regenerates a new one with a new csrf_token.

I updated the code to save a data array instead of a model instance. All is well now. Hopefully if someone runs into this problem my notes will help.

natcave left a reply on Calling A Model Relationship Refreshes The Csrf_token.

So, just one quick update. This problem seems to only be related to the User model. An example would be:


Calling the related user for some weird reason resets the authenticated user's csrf_token value. I've been digging all around for clues, still not finding anything. Any help will be appreciated. Thanks.

04 Feb
11 months ago

natcave started a new conversation Calling A Model Relationship Refreshes The Csrf_token.

I used to be able to call model relationships like:


    public function client()
        return $this->belongsTo('App\Client');


and it would simply return the related model. All of sudden I started getting csrf errors on pages that called relationship this way (it took a lot of troubleshooting to find out model relationships was the source of the problem).

I had to update the code lines handling these relationships to:


and now the csrf_token is fine, remains constant on these pages.

Any clues what might reset the csrf_token? The page is using the out-the-box web middleware. I'm not sure where else to investigate.

Eloquent and csrf feel like such a weird connection but updating the code style definitely fixed the error, temporarily anyways.

Could this be a problem with a recent update? I'm on v5.5.33.


17 Jan
1 year ago

natcave left a reply on Redis: Is There A Way To Retrieve An Array Of All Cached Items That Have A Key That Start With A Specific String?

Awesome! I found it.

I think I was thrown off because I was trying to access the data via cache (I'm using redis as my cache driver). It works when I start from redis.

Here's my solution:

$key_prefix = "laravel:shopping_cart:"; 
$shopping_cart = [];

foreach(Redis::keys("{$key_prefix}*") as $shopping_cart){
    $shopping_cart[substr($shopping_cart, strlen($key_prefix))] = unserialize(Redis::get($shopping_cart));

Thanks for your help @Cronix

natcave left a reply on Redis: Is There A Way To Retrieve An Array Of All Cached Items That Have A Key That Start With A Specific String?

Thanks for your response @Cronix,

I think I passed by that page while hunting for an answer. I'm looking for a way to retrieve the data within the laravel app, not on the command line. Sorry for not being clear.

Do you know of a way to retrieve the data via the Cache or Redis facades perhaps? If you have a quick code example that would help. Thanks.

natcave started a new conversation Redis: Is There A Way To Retrieve An Array Of All Cached Items That Have A Key That Start With A Specific String?

Maybe I have the wrong idea, but let's say I have these keys in redis:


Is there a simple way to iterate over any keys that start with "laravel:shopping_cart:" and return an array? Something like:

$shopping_carts = [
    1 => // laravel:shopping_cart:1 value,
    2 => // laravel:shopping_cart:2 value,
    3 => // laravel:shopping_cart:3 value,
    4 => // laravel:shopping_cart:4 value,
    5 => // laravel:shopping_cart:5 value,

I guess I could cheat and do a while loop starting from 0 and test every combination up to a point but that seems sloppy. I can't seem to find any info on retrieving existing values without first knowing the full key. Maybe I'm just missing it or perhaps is this where I get off the Redis train and head over to MYSQL?

Thanks for any insight!

16 Jan
1 year ago

natcave left a reply on ReflectionException After Deploy

I know this is an old post, I just wanted to leave a comment in case someone was searching for a solution. In my case I had forgotten to add some files to my repository before pushing to production (notably, a new middleware class in the mix). That explained why it worked fine locally because the app worked with the local files whether or not they were added to the repo. After adding, committing and pushing the new files the error went away. Hope this helps someone.

18 Dec
1 year ago

natcave left a reply on URL Generated In A Queue - Localhost Returned Instead Of Production Server

I was hacking away at this problem for a while now and found an odd occurrence that solved my problem. I'm documenting it here because this post came up as a top search result, so it may help someone else and shave off a few troubleshooting hours.

The urls in my queued emails were not matching the APP_URL variable in my .env file or the url value in my config/app.php file. (Quite frustrating)

I had built a new server on Forge which comes along with a "default" site, then added my "new" site on the same server with a similar .env file. Similar except of course for the APP_URL variable (you may see where this is going).

It turns out, the jobs starting on my "new" site were being picked up by a queue worker on the "default" site, thus plugging in the APP_URL variable set on the default site, which I assume for most people would be "http://localhost".

The solution for me was to simply turn off the queue worker on the "default" site.

So, the lesson here is to check if any other sites on the server are hijacking your queues, therefore plugging in the wrong APP_URL.

Hope this helps someone!

12 Dec
1 year ago

natcave left a reply on Laravel-Echo-Server Installation On Forge With SSL Enabled With The Redis Broadcast Driver And

Thanks so much for sharing @ashwinmram!

I just wish I found this post 16 hours ago. :-) You pretty much outlined all the steps I stumbled upon but I hit a roadblock trying to get it working with Forge. It's so much simpler when you have the steps outlined like this. For a moment I thought I would have to leave my terminal window open permanently lol.

I'm sure you'll help plenty of other newbs like myself. This topic is definitely worthy of a video for Jeffrey. Especially since a lot of the videos surrounding these topics are now a bit outdated. They're helpful to put you on the right track but they don't quite complete the picture for someone beginning a project today.

It works great so far, will keep an eye on it. Just dropping a line to show my appreciation. Thanks again!

02 Aug
1 year ago

natcave left a reply on Laravel 5 Creates A New Session After Each Request

@janise are you on a PC? That was related to my problem. If you're on a PC try laragon. You can read my saga here or just skip to the end.

24 Mar
1 year ago

natcave left a reply on [5.12] G Chrome Causes TokenMismatchException On Form Submit

Hey @jessiesanford

I can definitely relate. This problem was driving me nuts. I had to switch from Wamp to Laragon. Thankfully I haven't had the problem since. Laragon is pretty cool

Check this thread I created if you're curious about my saga lol. Scroll to the bottom for the happy ending.

11 Mar
1 year ago

natcave started a new conversation Laravel Identifies Database Column Type As DateTime But Is Actually Timestamp

I built a script in Laravel that renames database table column names.

Schema::connection()->table($table_name, function ($table) use ($value) { $table->renameColumn($value['from'], $value['to']); });

It crashes with an error:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: ALTER TABLE table CHANGE creation_timestamp created_at DATETIME DEFAULT 'current_timestamp()' NOT NULL)

The sql statement gives a clue, reporting creation_timestamp as a DATETIME field.

I ran this mysql statement at the command line:

SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'schema' AND table_name = 'table' AND COLUMN_NAME = 'creation_timestamp';

The result I get is: timestamp

I ran this code in Laravel:

echo DB::connection('mysql')->getDoctrineColumn('table', 'created_at')->getType();

The result is: DateTime

Any clue why Laravel is reporting DateTime when mysql clearly reports Timestamp?


09 Mar
1 year ago
08 Mar
1 year ago

natcave left a reply on Column 'name' In Field List Is Ambiguous With HasManyThrough

@Snapey Really? I didn't know. I'll check out pluck now. Thanks for the heads up.

natcave left a reply on Column 'name' In Field List Is Ambiguous With HasManyThrough

This did the trick:

$store->subcategories()->lists('', '')

When I remove "subcategories." before "name" (how I had it) I get the ambiguous field error.

Thanks for your help @Snapey and @bwrice. I appreciate it!

natcave left a reply on Column 'name' In Field List Is Ambiguous With HasManyThrough

Hey @Snapey

I'm calling $store->subcategories() in a blade template, specifically in a select drop down so I wrote it as $store->subcategories()->lists('name', 'id'). I get the error in my relationship definition.

natcave left a reply on Column 'name' In Field List Is Ambiguous With HasManyThrough

Thanks @bwrice

Yes, I do. I'm able to use $store->categories, $category->store and $subcategory->category. But I'd like to generate a list of $store->categories->subcategories, giving me a list of all subcategories related to a store. I know how to write it in MySQL but I was trying to follow the Laravel format. It seems it would work fine if I didn't have ambiguous names in both related tables.

natcave left a reply on Column 'name' In Field List Is Ambiguous With HasManyThrough

Thanks @Snapey

I'm not sure I follow. I'm not using select statements on any of the hasManyThrough relationships. Do you think I need a select statement in this case?

natcave started a new conversation Column 'name' In Field List Is Ambiguous With HasManyThrough

I have 3 tables. Let's call them "stores", "categories" and "subcategories".

categories has 3 columns: id, name and store_id

subcategories has 3 columns: id, name and category_id

So, both categories and subcategories have a "name" column.

I'm trying to get all the subcategories related to a store, so I'm using HasManyThrough in the store model:

subcategories() { return $this->hasManyThrough('App\Store\Subcategory', 'App\Store\Category'); }

This make sense, but I'm getting an error:

"Integrity constraint violation: 1052 Column 'name' in field list is ambiguous"

Is there anyway to tell Eloquent I'm only interested in the subcategory name?


27 Dec
2 years ago
21 Nov
2 years ago

natcave left a reply on Laravel Not Reading Session Cookie On Form Post In Chrome When Logged In With Remember Me


So far so good.

So the culprit is wamp all along.

It would be great if they put a warning for the newbies migrating from wamp/xampp

Thanks so much @ramouspeppy!

I'm back to work. :-)

04 Nov
2 years ago
31 Oct
2 years ago

natcave left a reply on Laravel Not Reading Session Cookie On Form Post In Chrome When Logged In With Remember Me

Hey @ramouspeppy

Unfortunately, no. I'm quite surprised more people haven't run into this problem, especially with all the praise Laravel gets.

I ended up disabling the Remember Me option. You can also disable Encrypt Cookies resulting in a smaller cookie size but I believe that will cause a security vulnerability.

If you find an answer, please share it. Thanks.

30 Sep
2 years ago

natcave left a reply on Laravel 5 Creates A New Session After Each Request

Hey @poupouxios

That's what I assumed, though I'm not adding any cookies. This happens with Laravel's cookies straight out the box. With Encrypted Cookies it makes the cookie parameters very long. My best guess is Chrome doesn't like it. I only noticed the problem when "Remember Me" is checked because that adds another encrypted cookie to the bunch and Chrome starts trimming in the middle of that cookie request. I went into detail on these posts:

Oddly, it hasn't caught the attention of anyone with the same problem. The key factors are Chrome + Laravel + Remember Me + Form Post.

natcave left a reply on Laravel 5 Creates A New Session After Each Request

Hey @poupouxios

I'm only building one laravel app. I tried changing the session cookie cookie name anyway, the same problem happens. In your case, did the cookie cut off like mine?

11 Sep
2 years ago

natcave left a reply on Laravel 5 Creates A New Session After Each Request

Hey @stan

I'm having a similar issue with Chrome cutting off the end of my cookie requests.

  • Firefox works fine.
  • Chrome only works when I don't have the remember cookie set.
  • Chrome will work if I manually delete the cookie, or if I turn off the Encrypt Cookies middleware (making the cookie values significantly shorter, but in turn disabling the security feature).

It seems to be an issue with the length of the cookie request. I've been racking my brain (and Google Search) at this for a week now, not getting any answers. Chrome is trimming my cookies down to 907 characters, yet every resource I find says I'm allowed 4KB.

Since your post seems similar to my issue, I'm just curious if you ever found a solution. Thanks @stan

10 Sep
2 years ago

natcave left a reply on Laravel Not Reading Session Cookie On Form Post In Chrome When Logged In With Remember Me

Here's the latest big clue yet:

Although Chrome looks like it's sending the entire encrypted session cookie, the end of the cookie value is missing in Laravel.

Here is the session cookie value Chrome sends:


Here is what the server reports:


Here is the entire cookie string:

remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IndDS1lrTkxVeGdMY1N1XC9uVERyVWx3PT0iLCJ2YWx1ZSI6Im5jVUtKdG5FZ01QbkJnTDNJV1RMMnhpd3Nja1wvS1NESVV6Rm83MjdXQmFcLyszSUtvOGVIM2V2MUtWd0VpelJUU3hXRVhhMmdCR1JINEFTUzBMTTd4TGVcL0lSeTZleUMwZXBxb1hsK25SRmtNPSIsIm1hYyI6IjNjNmNhNGE2YWMwNmEwZjI1ODI2ZjU3ODE2M2ZlNDIwZWMzNDM0MTMyMzdmNTFkYmQ0YTY1NzFkZDNhM2RjMGUifQ%3D%3D; _gat=1; XSRF-TOKEN=eyJpdiI6IlQ2aHpnNmN0V2w1bWtKZU03SnlKeFE9PSIsInZhbHVlIjoiVWJhdzVSOXFibDhSRTJRcVQrWXBOVkVzN3NGSnFmb1ZFRlozTzlcL29La0F4dXZmU1U5dGZTOXdHMUl5NSs4Q3NDK1dXTVdacll0c1NBeXNzTXYzTnBRPT0iLCJtYWMiOiI2NGQ4ZTQwOTZjOWIzZTljMTlkYjcxNTEyMjNmY2FjNjhiZGFkYjA4YzRkMmYwZDM1Yzc4ZTVlZGQ3ZmE5YWNkIn0%3D; web_session=eyJpdiI6Ik1BY1M0XC9Ma3luZjlBdGp6S3BOWWZ3PT0iLCJ2YWx1ZSI6IkU1SEh5dDNLZEFRTmVGTTNZM2NkRVRiUExleWRlbGpcL1M2clR2VWlaTm1pQnhrSnl1djVhc2wzU3l5NHNaMDhhVGphaUVadGlqZEpJMmxxV2VVWUtZQT09IiwibWFjIjoiODBiMTQ3OTc4ZWFjNmVlNDA1YjhlZDA1YmNiYmFiMmJlOTcxMTczMjI3ZjFhZDZmYTQ0NjNmMmYyMTU2NDFkMiJ9; _ga=GA#.#.##########.##########

The total length is 988 characters. It cuts off after 907 characters. The final "_ga" cookie (not related to Laravel) doesn't even make it in.

Since Laravel doesn't receive the entire session cookie, the decryption fails and sets the session cookie value to "null", killing the session, CSRF token, and so forth. I still don't know where the breakdown is. If this is a problem with Laravel, why doesn't the same problem happen in other browsers?

My best guess is: with the remember me cookie encrypted, session cookie encrypted, and XSRF-TOKEN cookie encrypted, Chrome hits a limit of what it will send with my form post and decides to trim the cookies, actually only sending part of the value of my session cookie, causing Laravel to fail the decryption and "null" the session. But is this a problem with Chrome sending the cookies or a problem with Laravel receiving the cookies? For the moment I'm stuck. Any ideas?

Here are my thoughts:

  • Is there a setting in PHP/Laravel to increase the amount of cookie data receivable with a post form? (I'm not sure if this is exists or for that matter why it would be browser specific, just a thought.)
  • Can I limit the size of the encrypted cookie value? (Since disabling the encryption lowered the string length and post submitted fine.)
  • Do I need to encrypt all these the cookies, or any of them? (since disabling the encryption did the trick, yet I don't want to leave the front door open).
  • Does Chrome's cookie delivery method differ from other browsers? (I'm trusting Chrome is sending all the cookies because that's what I see in the developer tools, but how would I know for sure?)
  • Is there a way to utilize local storage for these long strings instead of cookies? (If Laravel insists on sending these long strings that Chrome doesn't like, maybe they should be stored in local storage since there is plenty of space in there, though I'm not familiar with using local storage, maybe the protocol rules are more flexible than with cookies.)

I'm still hoping someone with more experience than I have can chime in and save me some steps. I'd appreciate it. Thanks!

natcave left a reply on Laravel Not Reading Session Cookie On Form Post In Chrome When Logged In With Remember Me

Ok. Here's another clue. In App\Http\Kernel.php I commented out this line in middlewareGroups:


Like magic it's working. I'm guessing the EncryptCookies middleware doesn't like the incoming cookie from Chrome.

Any thoughts how to troubleshoot from here?

09 Sep
2 years ago

natcave started a new conversation Laravel Not Reading Session Cookie On Form Post In Chrome When Logged In With Remember Me

I'm sorry for the long title. Although I've seen similar posts, this problem is specific.

I use Chrome for testing my projects. Seemingly out of nowhere I started getting TokenMismatch Exceptions when I submit forms. I knew this is could be because the CSRF token expires after some time. However this happens consistently, even if you submit the form immediately after the page loads. I eventually figured out the Exception only occurs when I checked "Remember Me" at login. Here are my test results:

Chrome + Uncheck Remember Me at login + Form Post = Success

Chrome + Check Remember Me at login + Form Post = TokenMismatch Exception

Chrome + Check Remember Me at login + Delete Remember Me Cookie + Form Post = Success

Firefox/IE + Check/Uncheck Remember Me at login + Form Post = Success

I figured out the reason why I'm getting TokenMismatch Exception. In between the form post I mysteriously lose the session. A new session generates automatically in the background, resulting in a new CSFR token, resulting in the TokenMismatch Exception.

I tried everything I could think of: deleting cookies/browser data restarting Chrome reinstalling Chrome restarting the server changing the Laravel session driver removing middleware reinstalling Laravel deleting the vendor folder starting a fresh Laravel project

Absolutely none of these fix or change the problem. I've been at this for 2 days now, scouring Google for clues. I can't find any answers, only a few posts from people who may have had the same problem but haven't yet reported an answer. Very strange.

Finally, after a night's sleep I found my biggest clue yet. I setup a temporary dd($request) to reveal the request variables. When the TokenMismatch Exception occurs, within the response output I get:

Request {+cookies: ParameterBag { #parameters: array[ larvel_session: null

Note the "null" for larvel_session. When the form posts successfully (on Firefox with Remember Me cookie), the dd($request) outputs:

Request {+cookies: ParameterBag { #parameters: array:[ larvel_session: <>

I checked the post headers in Chrome. Everything looks correct. Chrome is sending the session cookie to the server. However, the dd($request) shows me that there is a break somewhere. This is a great clue but I don't nearly know enough about Laravel to troubleshoot past this point. What might be going on behind the scenes to cause Laravel to "null" the incoming session cookie when receiving a form post from Chrome along with the remember me cookie. It's a mouthful, but a valid description.

If you have experienced this phenomenon, please share the steps you took to repair it. Also, if you have any suggestions on how to solve this problem I would truly appreciate it, as will the next person frantically Googling for clues. I've come so far learning Laravel, I'd hate to have to stop here. Thanks!

08 Sep
2 years ago

natcave left a reply on [5.12] G Chrome Causes TokenMismatchException On Form Submit

Hey. I'm having the same issue with Chrome. Very strange (and frustrating).

For me it's only when the "remember" cookie is set. If the remember cookie set and I delete it, the form processes properly.

Firefox works fine, only Chrome is kicking back the Token Mismatch.

Just curious if anyone figured this out.

19 Aug
2 years ago

natcave left a reply on Laravel Database Seeding With Real Street Addresses

Thanks @simondavies, I will do exactly that to grow the existing data.

I tried a few other options that didn't pan out. However, I did a little more digging and found this sweet function:


This function imports a database export file. So now I can export my database test table and save it in a folder within the project. Then ad this code to the migration file and it will pull the last export data right back in, instead of having to regenerate new fake data. Pretty cool.

I still would like to find a function that will create random real addresses but this is the next best thing.

Thanks so much for your help guys. If anyone stumbles on a solution, feel free to drop a line on this thread. Since I'm a newbie I won't be far. :-)

natcave left a reply on Laravel Database Seeding With Real Street Addresses

Thanks mstnorris. I see now that I don't have to use the faker, I can just replace it with an insert statement. Cool. I thought it would be nice to pull in random real addresses, just wondering if anyone else ran into this scenario and found an answer. In the meantime, I'll set it up manually. Thanks for your quick answer.

natcave started a new conversation Laravel Database Seeding With Real Street Addresses

Hey there. Laravel newbie here, having lots of fun learning. I'm building a store locator app. I was excited to learn that faker will generate fake street addresses. Awesome! However, when I tried map the results I quickly learned the addresses were not real. The latitude, longitude, postal codes, states, cities, and street addresses do not relate to one another, they are randomly put together. This would work great for a shopping cart app that needs shipping information, but for geocoding I need real street addresses. Any suggestions?

Here is my ModelFactory.php file