Sturm

Sturm

Member Since 1 Year Ago

Experience Points 110
Experience Level 1

4,890 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 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • 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

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    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.

27 Sep
1 year ago

Sturm started a new conversation Migration General Error: 1215 Cannot Add Foreign Key Constraint

I'm getting this error now when attempting to run a migration and I cannot, for the life of me, figure out why. I've spent time researching it and it appears that this is a very common issue with several different solutions. Unfortunately, none of the solutions I've found apply in my case.

For example, one solution suggests that the foreign key constraint is being created too soon--either before the column is created or even the table itself. Another suggests that the column to which the foreign key constraint is being applied doesn't match the reference table's column precisely. And the list goes on. Sadly, these don't appear to have any bearing on my situation, so I'm hoping someone here can help.

I have a lookup table called item_statuses (As I understand it, table names should be plural and snake case) that I recently created and populated with a few records. I also have a line_items table that has existed for years and has many records. I'm attempting to run a migration that adds a column to the line_items table, referencing the primary key of the lookup table. It then adds a foreign key constraint to that new column.

I've checked to make sure the datatypes are the same, that the column is created before the constraint is added, and that the naming of everything is consistent with guidelines. I honestly cannot figure out why running this simple migration is giving me a General error: 1215.

Here is the up() method of the migration:

    public function up()
    {
        Schema::table('line_items', function (Blueprint $table) {
            $table->string('item_status_id')->nullable()->after('machine_num');
        });
        Schema::table('line_items', function (Blueprint $table) {
            $table->foreign('item_status_id')
                ->references('id')
                ->on('item_statuses');
        });
    }

Can anyone please help me discover what I'm not seeing?

28 Aug
1 year ago

Sturm left a reply on Saving The Opened/closed Status Of A Sidebar

Thanks for the fast replies, @jlrdw and @Cronix! As it turns out, I probably shouldn't be using PHP for this task, after all. Since there's already a handler for this event in the admin template's JavaScript file, I figured I would just take advantage of that and use a JavaScript cookie. So I set about adding the JS-Cookie library to handle it.

However, after investigating the function that handles the sidebar toggler, I see that this admin template author has already been using the JS-Cookie library and, indeed, storing the sidebar state with each click. He even had code for retrieving that cookie and adding the appropriate class to the <body> tag; it was just commented-out. So I uncommented it and it seems to work, just with a delay. That is, the page then loads with the sidebar open for a second, then it collapses, presumably once it reaches that point in the code.

I think I’ll be okay with the delay, though. I don’t know what else to do about it, but it probably won't be a huge deal. Thanks again!

Sturm started a new conversation Saving The Opened/closed Status Of A Sidebar

This seems like the kind of problem that's been solved a hundred times over, but since I'm a n00b, I need some hand-holding.

I've got a sidebar that opens/collapses when a hamburger icon in the header is clicked. This is obviously accomplished in JavaScript. However, going to another page (route) resets the sidebar back to its default--opened.

There must be some way to store the user's preference if they want the sidebar collapsed so just icons in it are showing. My immediate thought is to use a SESSION variable. If that's not a good idea, then perhaps a cookie. If that, too, is not considered a good practice, then can someone please tell me what is?

More importantly, however, is where to store the variable. I've pretty much already got the how from the Laravel docs and from many Google searches (i.e., session(['sidebar_status' => 'page-sidebar-closed']) or Cookie::make('sidebar_status', 'page-sidebar-closed'). What I cannot find nor figure out is how to have the app detect when a user clicks/taps on the hamburger icon/button, read whether or not the 'page-sidebar-closed' class already applied to the tag, then reverse that and store it somewhere (session, cookie, whatever) while also allowing the JavaScript to execute and perform the action. The stored variable can then be read back into the tag's class list as either an empty string or a the 'page-sidebar-closed' string.

I've been told there's no need to create a Controller for this, and I haven't yet gotten any answer on whether or not I need to create and Event/Listener combo. Although I doubt I should do that for just a simple thing like this. So what's the step-by-step that I'd need to for this? Again, I apologize in advance for such a simple request from a newcomer.