zachleigh

zachleigh

Member Since 4 Years Ago

Experience Points 217,670
Experience Level 44

2,330 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 977
Lessons
Completed
Best Reply Awards 244
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.

25 Oct
6 months ago

zachleigh left a reply on Vue Component Not Displaying Properly

My guess is that this is your problem:

Maybe this would work:

 <a class="sidebar_related_content_image" :href="'/conducta-canina/' + post.slug"  :style="'background-image:url(' + post.slug + ');'">

zachleigh left a reply on Mapping Values In A Multi Dimensional Array

$m is not an object. It is an array. Should probably be:

$newArray = collect($array)->map(function($m) {
        [
            'code' => $m['code'],
            'label' => $m['label'],
            'amount' => 1.00, // for testing
            'nodes' => $m['nodes'],
        ];
    });

zachleigh started a new conversation ValidationException Bubbling Up To Excepltion Handler

I have a weird issue that I've never seen before. I use request objects to do form validation. I expect ValidationExceptions thrown by my request objects to be caught internally and turned into appropriate error message responses. Everything is fine in development, but on production when I set APP_DEBUG to false, ValidationException objects bubble up to the exception handler and result in error pages. Here's a request class I'm using;

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MailRecipientUpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'current_email' => 'required|email',
            'new_email' => 'required|email|unique:mail_recipients,email'
        ];
    }
}

And a method signature from a controller:

public function update(MailRecipientUpdateRequest $request)

No funny stuff going on there. So anybody have any idea why this is happening and what I can do about it? Would really appreciate a hand.

08 Jan
1 year ago

zachleigh left a reply on Laravel Doesn't Pass Request Object

Surround your code in three backticks:

code

zachleigh left a reply on Upload Large Csv File To Mysql With Laravel

Upload the file and use fgetcsv to parse it and fill your table. The PHP League has a nice package to make parsing csv a little easier: https://csv.thephpleague.com/9.0/.

28 Dec
1 year ago

zachleigh started a new conversation Full Screen (landscape) On Mobile Broken

If I watch a video in full screen landscape mode on mobile, a frozen screen artifact is created and displayed in the lower left-hand portion of the screen. If I rotate the phone to leave landscape mode, the artifact covers the playing video. This only started occuring today (although this is first time I tried to watch on mobile in about a week).

Asus Zenfone, Android 7.0, Chrome

13 Dec
1 year ago

zachleigh left a reply on Send Notification 'exactly' 1 Hour After DateTime Field

a) A single database call every minute is nothing. If you're really worried about it, do it every five minutes and use a < instead of = in your query.

b) What is the format of the last_sent_out_at field? is it also 'Y-m-d H'? Because you're using an = sign, it would have to be an exact match.

zachleigh left a reply on Where Can I Learn AI Like Laracasts?

Jeffery has said several times that he would prefer to keep this site focused on Laravel, PHP, and occasional other web dev technologies. That's part of the appeal in my opinion. I would guess that he is not planning on branching out into AI or anything else far removed from his target audience.

12 Dec
1 year ago

zachleigh left a reply on Laravel Form Or HTML

I don't use it anymore. I found I spent quite a lot of time reading the Collective docs trying to figure out how to do things that I already knew how to do with plain HTML. Also, sometimes its slow to be updated. The final nail in the coffin for me was when I upgraded an app to the latest major Laravel release only to find out that Collective wasn't there yet.

zachleigh left a reply on Unknown Column 'id' In 'field List' - Laravel Notifications

What does your User table look like? Is there any more to that message, like a stack trace or raw SQL query?

08 Dec
1 year ago

zachleigh left a reply on Multi Auth User Type

This would be in the controller.

Also how does this determine what type of user it is from the table?

That depends on how you set it up. In your database, how do you distinguish between user types?

zachleigh left a reply on Trouble Using Api Method Not Allowed Exception

In the console, what does php artisan route:list show?

zachleigh left a reply on Multi Auth User Type

Why not just use an if statement?

if ($user->type === 1) {
 return redirect()->route('usertype1.home');
} elseif ($user->type === 2) {
  return redirect()->route('usertype2.home');
}
11 Nov
1 year ago
27 Oct
1 year ago

zachleigh left a reply on Gate Auth In Loops

Why check twice? Its the exact same check so just put it in one block:


@foreach($routes as $route)
    <tr>
        <td><strong> {!! $route->id !!}</strong></td>
        <td><strong> {!! $route->zone->zone !!}</strong></td>
        <td><strong> {!! $route->route_number !!}</strong></td>
        <td><strong> {!! $route->end_time_am !!}</strong></td>
        <td>{!! $route->end_point_am !!}</td>
        <td>{!! $route->start_time_pm !!}</td>
        <td>{!! $route->start_point_pm !!}</td>
        <td>{!! $route->end_time_pm !!}</td>
        @can('update', $route)
            <td class="hidden-xs" style="width:2%;">
                <a title="Edit"
                   href="{!! URL::route('update_route', $route->id) !!}"
                   class="pull-right"><i class="fa fa-pencil-square-o fa"></i>
                    <a>
            </td>
            <td class="hidden-xs" style="width:2%;">
                <a title="Remove"
                   href="{!! URL::route('remove_route', $route->id) !!}"
                   class="pull-right"><i class="fa fa-times"></i>
                    <a>
            </td>
        @endcan
    </tr>
@endforeach 
23 Oct
1 year ago

zachleigh started a new conversation Catch Notification Failures?

I'm sending out notifications and would really like to be able to log failures. As described in the docs, I'm using events to log when notifications are sent, but have not found a way to get the notification status. Anybody know how to do this?

13 Oct
1 year ago

zachleigh left a reply on Dealing With Complexity In Controllers

@kataklys

The User model is responsible for the users table database records so having a bulk create method on the class makes perfect sense to me.

09 Oct
1 year ago

zachleigh left a reply on Axios.get Database Filtering

You should really be taking advantage of Eloquent and the query builder: https://laravel.com/docs/master/queries

zachleigh left a reply on Axios.get Database Filtering

Just a db query:

Order::where('order_id', '>', 1000000)->get();
08 Oct
1 year ago

zachleigh left a reply on Axios.get Database Filtering

Send a get parameter, maybe order_id_min, and filter them in your database query.

zachleigh left a reply on How To Get Id From Auth::user() ?

You arent actually getting the records. You're only getting a builder instance. You need to call get.

$channels = Channel::where('user_id', '=', Auth::user()->id)->get();

zachleigh left a reply on How To Get Id From Auth::user() ?

What happens when you run the above code?

zachleigh left a reply on Dealing With Complexity In Controllers

@kataklys

When submitting a form, you would need to have the user information separated from any other information anyway.

[
    'users' => [
        [user 1 data],
        [user 2 data],
        etc.
    ],
    'something else' => [
        //
    ],
]

So in your form request the logic to validate the users information would be namespaced.

'user.*.email' => 'required',
'user.*.name' => 'required|unique',
etc.

So if you do end up making users from some other point in your app, you could simply put the user validation rules on a parent request class or in a trait and merge them in any other rules needed for the request.

The static method on the User model would encapsulate all the logic for starting the transaction, looping through the users and firing the event. This way, if you did end up creating users from some other point in the app, it would be as easy as User::createBulk($data).

zachleigh left a reply on Dealing With Complexity In Controllers

I would move the validation to a request class, put the user creation logic in a static model method and fire an event (UsersWereCreated) to do anything else like send mail. Every class should ideally have one distinct responsibility. Request class manages the incoming request. Controller class decides what to do with requests. Model is responsible for modeling database records. UsersWereCreated event class manages event data. SendWelcomeEmail event listener sends email to new users. This means that you can very easily unit test every part of this process and hopefully keep them distinct from one another.

At least for me, when I find myself saying 'this class does A AND B AND C', then I know its time to consider a refactor. In some cases it makes sense to not refactor, but if your controller method is making you uncomfortable and is doing multiple tasks, its probably worth creating other classes to perform bits of your logic.

zachleigh left a reply on Validate Birthday (dd/mm/aaaa)

Are you validating a request? If so, use the the date_format validator: https://laravel.com/docs/master/validation#rule-date-format

zachleigh left a reply on Namespace Declaration Statement Has To Be The Very First Statement

What about a whitespace after <?php>?

<?php //<- anything here?
07 Oct
1 year ago

zachleigh left a reply on Artisan Call In Loop

My guess is that you are setting the config value in one app instance but when you call Artisan::call, it is actually creating another app instance to run the command in. In this newly created app instance, your config value has not been changed.

Solution could be to create a custom migrate command where you first change the config value and then run the migration by calling the framework classes rather than through another artisan call.

zachleigh left a reply on Namespace Declaration Statement Has To Be The Very First Statement

Do you have any whitespace between you opening php tag and the namespace declaration?

zachleigh left a reply on Migrate & Seed Only Once?

I extract the DatabaseTransactions into my own trait to gain control over it:

<?php

namespace Tests;

trait DatabaseTransactions
{
    /**
     * Handle database transactions on the specified connections.
     */
    public function beginDatabaseTransaction()
    {
        $database = $this->app->make('db');

        foreach ($this->connectionsToTransact() as $name) {
            $database->connection($name)->beginTransaction();
        }

        $this->beforeApplicationDestroyed(function () use ($database) {
            foreach ($this->connectionsToTransact() as $name) {
                $database->connection($name)->rollBack();
            }
        });
    }

    /**
     * The database connections that should have transactions.
     *
     * @return array
     */
    protected function connectionsToTransact()
    {
        return property_exists($this, 'connectionsToTransact')
            ? $this->connectionsToTransact : [null];
    }
}

If you try to use the DatabaseTransactions trait that comes with Laravel, it will be registered with the test runner and this will not work. In my TestCase class, I do the following:

<?php

namespace Tests;

use Tests\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, DatabaseTransactions;

    /**
     * If true, setup has run at least once.
     *
     * @var boolean
     */
    protected static $setUpRun = false;

    /**
     * Set up the test.
     */
    public function setUp()
    {
        parent::setUp();

        if (!static::$setUpRun) {
            \Artisan::call('migrate:refresh');

            \Artisan::call('db:seed', ['--class' => 'TestDatabaseSeeder']);

            static::$setUpRun = true;
        }

        $this->beginDatabaseTransaction();
    }
}

Basically, if its the first run, we're going to migrate and run a seeder to get everything set up. Otherwise, we'll just start database transactions.

11 Sep
1 year ago

zachleigh left a reply on Dusk Suddenly Can't Find Elements That Need Scrolling To Access

@danielbaylis Excellent. Had no idea Browser was macroable. The scrollTo one works perfectly for my situation. Thanks a lot!

zachleigh left a reply on VueJS Component VS Laravel Blade

If you don't want page refresh after the user changes something, go with Vue. You should check out the current build a forum series on the site. It covers exactly what you are asking about.

https://laracasts.com/series/lets-build-a-forum-with-laravel

zachleigh left a reply on Is It Possible To Shuffle Lazy Loading Collection?

In your code, $stack is a model. If you check the api out (link below) you'll see that load returns the model. So you are calling shuffle on a model, which is going to fail.

https://laravel.com/api/5.3/Illuminate/Database/Eloquent/Model.html#method_load

zachleigh left a reply on Dusk Suddenly Can't Find Elements That Need Scrolling To Access

@bashy Yes, I tried that and had no luck.

@danielbaylis Could be a Chrome issue. Don't know if I feel like managing outdated Chrome versions just to make tests pass though.

I found that same GitHub issue and one comment in there suggested first using type near the element to draw focus. All my failing tests are on forms so I type something near the button before doing the click. Its dirty and I don't like it, but it works.

10 Sep
1 year ago

zachleigh started a new conversation Dusk Suddenly Can't Find Elements That Need Scrolling To Access

I updated composer dependencies yesterday and since then am getting this error on several tests:

Facebook\WebDriver\Exception\UnknownServerException: unknown error: Element is not clickable at point (1450, 2309)

Test code:

$browser->visit(new EditPage()
    ->click('#add');

The element it is trying to access (#add) is simply down the page a bit. It is fully visible and if I pause the test before the click and manually scroll down, the test continues as normal. I'm not 100% sure if the update yesterday is related to the issue, but I can't think of anything else that may have caused this to happen so suddenly. Any body else experiencing this? Any ideas on how to fix it?

05 Aug
1 year ago

zachleigh left a reply on How To Add Additional Librery To Bootsrap Js

bootstrap.js is just a js file that you can use to load up libraries etc. It is included at the top of app.js so anything you put in there will be done before the rest of your js.

zachleigh left a reply on How To Redirect To Another Controller Action?

Just tried my above code and it works fine here.

zachleigh left a reply on How To Redirect To Another Controller Action?

But the index method works fine?

zachleigh left a reply on How To Redirect To Another Controller Action?

Does this work?

public function find(Request $request) {
    return $this->index($request, $events, $searchConf);
}

This will work in other frameworks. Not sure about Laravel, but I don't see any reason why it wont.

zachleigh left a reply on Method Not Loading

Glad you got it working!

zachleigh left a reply on How To Add Additional Librery To Bootsrap Js

Did you initiate it anywhere? From the docs:

new WOW().init();

zachleigh left a reply on Method Not Loading

What does this do?

$this->submission->generateReport();

zachleigh left a reply on Method Not Loading

What happens when you call the handle method?

zachleigh left a reply on Echo Result From Table To Blade

What value do you get if you dump our $stove->stove_defra?

{{ dd($stove->stove_defra }}
31 Jul
1 year ago

zachleigh left a reply on How To Use Trim When I Used Validation In Laravel ?

Please be more specific and show us your code.

zachleigh left a reply on How To Handel BadMethodCallException

Please show us Handler.php.

zachleigh left a reply on Better Web Dev Workflow

What specifically are you struggling with?

30 Jul
1 year ago

zachleigh left a reply on Upload Files To Production Server

Use git. Its a great way to update your site.