Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

zachleigh

Hire Me

Experience

204,780

248 Best Reply Awards

  • Member Since 2 Years Ago
  • 855 Lessons Completed
  • 5 Favorites

13th December, 2017

zachleigh left a reply on Send Notification 'exactly' 1 Hour After DateTime Field • 15 hours ago

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? • 15 hours ago

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.

12th December, 2017

zachleigh left a reply on Laravel Form Or HTML • 1 day ago

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 • 1 day ago

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

8th December, 2017

zachleigh left a reply on Multi Auth User Type • 5 days ago

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 • 5 days ago

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

zachleigh left a reply on Multi Auth User Type • 5 days ago

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');
}

11th November, 2017

zachleigh left a reply on Call Controller Method From Vue • 1 month ago

Ajax.

27th October, 2017

zachleigh left a reply on Gate Auth In Loops • 1 month ago

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 

23rd October, 2017

zachleigh started a new conversation Catch Notification Failures? • 1 month ago

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?

13th October, 2017

zachleigh left a reply on Dealing With Complexity In Controllers • 2 months ago

@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.

zachleigh left a reply on Lesson Request: Testing Vue • 2 months ago

Thanks @JeffreyWay!

9th October, 2017

zachleigh left a reply on Axios.get Database Filtering • 2 months ago

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 • 2 months ago

Just a db query:

Order::where('order_id', '>', 1000000)->get();

8th October, 2017

zachleigh left a reply on Axios.get Database Filtering • 2 months ago

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() ? • 2 months ago

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() ? • 2 months ago

What happens when you run the above code?

zachleigh left a reply on Dealing With Complexity In Controllers • 2 months ago

@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 • 2 months ago

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) • 2 months ago

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 • 2 months ago

What about a whitespace after <?php>?

<?php //<- anything here?

7th October, 2017

zachleigh left a reply on Artisan Call In Loop • 2 months ago

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 • 2 months ago

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

zachleigh left a reply on Migrate & Seed Only Once? • 2 months ago

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.

11th September, 2017

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

@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 • 3 months ago

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? • 3 months ago

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 • 3 months ago

@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.

10th September, 2017

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

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?

5th August, 2017

zachleigh left a reply on Any Tutorials On Laravel Blog • 4 months ago

zachleigh left a reply on How To Add Additional Librery To Bootsrap Js • 4 months ago

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? • 4 months ago

Just tried my above code and it works fine here.

zachleigh left a reply on How To Redirect To Another Controller Action? • 4 months ago

But the index method works fine?

zachleigh left a reply on How To Redirect To Another Controller Action? • 4 months ago

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 • 4 months ago

Glad you got it working!

zachleigh left a reply on How To Add Additional Librery To Bootsrap Js • 4 months ago

Did you initiate it anywhere? From the docs:

new WOW().init();

zachleigh left a reply on Method Not Loading • 4 months ago

What does this do?

$this->submission->generateReport();

zachleigh left a reply on Method Not Loading • 4 months ago

What happens when you call the handle method?

zachleigh left a reply on Echo Result From Table To Blade • 4 months ago

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

{{ dd($stove->stove_defra }}

31st July, 2017

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

Please be more specific and show us your code.

zachleigh left a reply on How To Handel BadMethodCallException • 4 months ago

Please show us Handler.php.

zachleigh left a reply on Better Web Dev Workflow • 4 months ago

What specifically are you struggling with?

30th July, 2017

zachleigh left a reply on Upload Files To Production Server • 4 months ago

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

29th July, 2017

zachleigh left a reply on Laravel 5.4 File Put Content • 4 months ago

What do your permissions look like? ls -l in console.

zachleigh left a reply on Laravel 5.4 File Put Content • 4 months ago

Dont use 777 on a production server.

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

zachleigh left a reply on Run "where Like" In A Table Inserted With The "with" • 4 months ago

You should use a join instead of eager loading. https://laravel.com/docs/master/queries#joins

zachleigh left a reply on Laravel Unwanted Stuff Grrrr • 4 months ago

You can do whatever you want :) bootstrap.js is simply a file to load up js libraries. Remove it if you don't want it. If you don't want to use laravel mix, the yes, you can remove all associated files. Id recommend keeping that though. It makes building front end stuff a breeze. But, its entirely up to you.

zachleigh left a reply on Laravel Unwanted Stuff Grrrr • 4 months ago

Remove whatever you dont want from package.json before running npm install. Then just delete the unwanted stuff from bootstrap.js and app.js.

This is a common complaint and is being dealt with in Laravel 5.5: https://laracasts.com/series/whats-new-in-laravel-5-5/episodes/4

zachleigh left a reply on Call JS Function At The End Of The Page (AJAX Session Check) • 4 months ago

You can use remember me to prevent users from having to log in again. This works, but the csrf token can still expire. For this you can try something like Caffine: https://caffeine.forlaravel.com

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.