Drfraker

Drfraker

Member Since 5 Years Ago

Bozeman, MT

Experience Points
116,050
Total
Experience

3,950 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
1171
Lessons
Completed
Best Reply Awards
32
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 24
116,050 XP
08 Aug
1 month ago

Drfraker left a reply on Database Migrations And Deploying To A To Load-balanced Group.

I use laravel envoyer. It can run deployment hooks on specific servers. So you can create a deployment hook that runs the command php artisan:migrate one of your servers that is sitting behind your load balancer. I'm sure you could script this behavior manually in your deployment scripts.

26 Jun
2 months ago
25 Jun
2 months ago

Drfraker left a reply on Laravel Horizon Only Work The Queue Between Certain Hours

^^ Not sure. Google is your friend. :)

21 Jun
3 months ago

Drfraker left a reply on How To Avoid Interface Segregation In My Case? (SOLID)

Then give it a implementation of BInterface. Just because the create function has AInterface passed in doesn't mean you have to new up SuperClass with it.

$class = new SuperClass(new ThingThatImplementsBInterface());

Drfraker left a reply on Forge Admin Method

I believe I remember a podcast where Taylor said that it uses ansible behind the scenes. https://www.ansible.com/overview/how-ansible-works

Drfraker left a reply on Looking For Elegant PHP Process Runner

I wonder if leveling up your OOP skills could help you sort out the issues you're having. This was a great course: https://laracasts.com/series/object-oriented-bootcamp-in-php. I remember when I was feeling overwhelmed like this, it was due to lack of understanding of how to make objects that worked and write tests.

I would highly recommend watching the OOP series, getting Adam Wathan's course "Test Driven Laravel" and writing tests for your code (if you aren't already).

Those 3 things will help you clean up the mess. Warning: It may not be quick! :)

Good luck.

Drfraker left a reply on Laravel Horizon Only Work The Queue Between Certain Hours

Your queue worker probably isn't where the business logic of sending communications should live. Maybe the logic that sends the communication should delay jobs so that they are sent during business hours. The queue shouldn't have to care at all about that stuff.

https://laravel.com/docs/5.1/queues#delayed-jobs

09 Jun
3 months ago

Drfraker started a new conversation New Metric For Leaderboard

I think it would be cool to have a leaderboard metric that shows ranking of (Best reply award count / reply count) * 100. Higher scores would indicate higher quality answers.

Or maybe you could think of something similar that would be a better indication of quality answers...

Drfraker left a reply on Unit Test For Many To Many Relationship

$role = factory('App\Role')->create();

$this->assertInstanceOf(User::class, $role->users->first()); // You were retrieving a collection of users, which is an instance of an `Eloquent\Collection`, not a `User`

Drfraker left a reply on Envoyer Deployment Not Showing

Envoyer restarting PHP-fpm is a setting on the project level. You may have not checked that box. It does sound like an opcache thing though.

Drfraker left a reply on Queue WithChain, Can't Make It Run Sequentially

Try dropping your processvideos queue to one process. I think you'll get the desired result in that case. However, that slightly defeats the purpose of running jobs like this on a queue.

Drfraker left a reply on Laravel And Ajax

off hand, write tests, and perform server side validation in controller or using form requests.

Drfraker left a reply on How To Use Php:artisan Outside App Folder?

FWIW, I've worked on an app with that folder structure before. Everyone on the team hated it. We fought against the framework conventions all the time and slowly refactored away from it. It was $$$$ wasting.

You might have a great reason to be doing this. If so, go for it. If not, consider it carefully.

Drfraker left a reply on How To Use Php:artisan Outside App Folder?

^^ just tested, doesn't work.

Drfraker left a reply on How To Use Php:artisan Outside App Folder?

You should be able to do that from the root artisan. php artisan make:controller modules/Blog/Http/Controllers/TestController. Not sure though, also it seems like / might have to be escaped. Give it a shot.

Drfraker left a reply on How To Make Laravel Nova Filters And Actions Only For Resource Itself?

You should be able to use the canSee() method and return a boolean based on the request()

return (new Action::class)->canSee(function() {
    return request()->url() === '/resources/events';
});

Or something like that. Obviously not tested.

22 May
4 months ago

Drfraker left a reply on Using WhereIn And Comma Separated Values

whereIn() is not going to work like that. Here's a better approach. Set up a keywords table and a pivot table for keyword_post. Then set up a manyToMany relationship a post hasMany Keyword and keywords hasMany Post. For related posts you would use the pivot table to query. This approach will allow the database to do the heavy lifting with the added benefit of not having duplicated keywords for posts. Tables:

posts

id

status

keywords

id

name

keyword_post

id

keyword_id

post_id

14 Mar
6 months ago

Drfraker left a reply on Laravel Forge Load Balancer Problems

In case anyone else has a problem like this, the issue was that I added the public IP address to the trusted proxies middleware. Chris Fidao was kind enough to show me that I needed to add the private IP address to the array.

Drfraker started a new conversation Laravel Forge Load Balancer Problems

I added a load balancer to my server stack using forge. Now with each page load all of the forms in the page have unsecure urls. this is the error that is showing up in the console.

Mixed Content: The page at 'https://domain.com/clients' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://domain.com/userSettings/update'. This endpoint should be made available over a secure connection.

I have set up the TrustProxy middleware and added the IP address of the load balancer to it, but it still is not working. Any advice?

21 Feb
7 months ago

Drfraker left a reply on How Do You Guys Create Admin Panel In Laravel

I've used backpack and Nova. I can say Nova is worth the $$.

30 Jan
7 months ago

Drfraker left a reply on Run ZSH Command From Laravel

If you want to move the file to another server you'll have to use the scp command which allows you to transfer files between servers over ssh. Here's the basic syntax:

scp -r source_folder [email protected]:destination_folder

29 Jan
7 months ago

Drfraker left a reply on Best Practices For Laravel API Sandbox

@themsaid, a core laravel developer, just published an article covering a deep dive into database connections. This article might give you some good ideas to move forward with.

https://divinglaravel.com/understanding-how-laravel-configures-database-connections

28 Jan
7 months ago

Drfraker left a reply on Not Seeing How To Disable Caching Locally

@DAVESTEAD - If you run the command php artisan config:cache it will clear the config cache and then re-cache it. You want to runphp artisan config:clear that will clear it but not re-cache it.

Drfraker left a reply on Name Of Model Which Tracks Downloads...

How about FileActivity With this name you could conceivably add more logic to aside from just download count and it would still make sense.

//table
file_activities
id
file_id
type // string to add the type of activity, in your case would be 'downloaded'
created_at
updated_at

27 Jan
7 months ago

Drfraker left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

I can help you live on https://devallies.com . I'm drfraker on there too. Might be easier.

Drfraker left a reply on How Do I Get A Count Of How Many Columns Are (or Aren't) Null In A Query?

$query->whereNull('column_name')->count();

Drfraker left a reply on Vue-select A Select2 Library With Laravel

I think what you want to do is wrap the vue-select component in your own custom component. Then within your custom component, you can create methods for retrieving data etc with ajax calls. I could help you live on https://devallies.com, my username is drfraker on there too. I'll only be available for the next hour though.

26 Jan
7 months ago

Drfraker left a reply on How Do I Check If A Model Has A Job On The Queue?

Without storing the state of the model being in the queue, in some state management system (database, redis, etc), and then updating that state to tell it that the model isn't in the queue anymore, I'm not sure how you're going to achieve what you're original question was about.

I'm not sure why you're thinking that you can process millions and millions of rows of data without some complexity in your app ?!?!

Good luck...

25 Jan
7 months ago

Drfraker left a reply on How Do I Check If A Model Has A Job On The Queue?

You could use queue before and after events to keep track of which jobs are in the queue at any given time. Add them before they run and remove them after they run. Here's the link and an example from the docs. This isn't tested code, just pseudo code but you get the idea. I'm not sure if the Queue::before() event only runs when the job is beginning to process, if so you would want to add the model to the database as being queued before you dispatch the event and then use the after function to remove it once it is processed.

https://laravel.com/docs/5.7/queues#job-events


<?php

namespace App\Providers;

use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Queue::before(function (JobProcessing $event) {
        // get the model from the payload
        $model = $event->job->payload();
            // store the model in the db as queued
        });

        Queue::after(function (JobProcessed $event) {
        // get the model from the payload
        $model = $event->job->payload();
            // remove the model row from the database
        });
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}


Drfraker left a reply on Free Domain Emails

I haven't done this but I think you might be able to use a service like Mailgun, which has a nice free tier, and this package to get the job done. https://laravel-news.com/laravel-inbound-email

Let me know how it goes. I might use this setup for a new side project I'm working on.

23 Jan
7 months ago

Drfraker left a reply on Axios Always Returns A Null Data And Status

I think the issue is that your nativescript can't reach your application because it's a different app. I've solved this before using valet and running valet share and then using the ngrok IP address for the URL in nativescript.

Give that a try...

[update] Use the URL provided by ngrok not the IP address.

Drfraker left a reply on DB Schema: Multiple Choice And Fill In The Blank Q & A

If the answer will only ever be attributed to the user that gave the answer, why not put user_id on the answers table. Skip the pivot table altogether. A pivot table is more for when you might have an answer that could be attributed to more than one user, one to many or many to many relationships. Correct me if I'm wrong about that though...

16 Jan
8 months ago

Drfraker left a reply on Do Modified Collections Maintain The Same Keys As Original?

I'm not sure what you're referring to when you say "keys". But here's an attempt to clarify for you.

If you have a collection of 30 items keyed 0-30 and you remove the odd keys using a filter method on the collection you will have a collection of 1-29 only containing the odd keyed items. Those keys and the items they refer to will be the same as they were before the filter was run.

If you mean something else, try to elaborate on the question.

Tip: When you're unsure how something like this works consider using php artisan tinker. Once in the REPL you can play around with collections and transform them and see the results. It's probably faster than asking the question here and waiting for a reply :)

Drfraker left a reply on [CLOSED] How To Allow CSS Content To Be Rendered In My Local Apache Web Server With Chrome?

I know I don't speak for everyone, but I'm not chasing down links on stack overflow in order to answer your question here.

Drfraker left a reply on Storage Problem

I think if you familiarize yourself with this: https://laravel.com/docs/5.7/filesystem you will be very happy with the time you spent on it. You're making things hard on yourself with that code.

08 Jan
8 months ago

Drfraker left a reply on How To Speed Up This Sql Query

@JLRDW - the list() function assigns variable as if they were an array. You can see that the getFilteredNotes() function that is being called returns an array. Well by using list($query, $totalcount) the variables are set automatically from the return value.

Drfraker left a reply on How To Speed Up This Sql Query

@CLICK - Wow thanks for the in depth reply.

I will look at the article and see about the simple paginator instead of length aware. I think it is the count() that is taking so much time. I'll also check my indexes to ensure they are set up correctly. Also, yes the filter is using LIKE %search% maybe I'll have to find a better way to do that too.

Drfraker started a new conversation How To Speed Up This Sql Query

In my application ( which is multitenant) I have a query that can take up to 10 seconds depending on the number of rows in the database for a given office. I'd like to speed this up but I'm not sure how to do it. The table for this query "notes" is quite large and has around 800,000 rows in it. Additionally, the note_text on the notes table can be quite large.

Here's the controller, I believe the code that is slow is in the getFilteredNotes($request) method, and possibly related to getting the count. But I'm not sure. It is difficult to test because in development environment I don't have nearly as much data in the notes table.

My questions:

  1. Is there a clear problem with the query that is making it slow?
  2. Is there a way to measure this query for debugging without replicating production data? (Due to privacy regulation, I really don't want production data on my machine)
  3. Could removing the note_text field have an effect on the time of the query to complete?
<?php

namespace App\Http\Controllers\Api;


class NotesController extends Controller
{
    private $note;

    public function __construct(NoteRepositoryInterface $note)
    {
        $this->note = $note;
    }

    public function index(Request $request)
    {
        $paginationPage = $request->page ?? 1;
        $take = 25;

        list($query, $totalCount) = $this->getFilteredNotes($request);

        $notes = $this->getPaginationData($query, $take, $paginationPage);

        $clientIds = $notes->pluck('client_unique_id')->unique()->reject(function ($id) {
            return ! $id;
        });

        $clients = app()->make(ClientRepositoryInterface::class)->getClients($clientIds);

        $notes->map(function ($note) use ($clients) {
            $note->setRelation('client', $clients->where('api_unique_id', $note->client_unique_id)->first());
        });

        return new LengthAwarePaginator($notes, $totalCount, $take, $paginationPage);
    }
  

    /**
     * Get the notes for the view and filter by search text and user.
     *
     * @param Request $request
     * @return array
     */
    private function getFilteredNotes($request)
    {
        $filter = $request->filter;

        $query = Note::with('staff')
            ->select([
                'id',
                'client_unique_id',
                'user_id',
                'created_at',
                'deleted_at',
                'service_date',
                'note_text',
                ])
            ->when($filter, function ($q) use ($filter) {
                return $q->clientName($filter)
                    ->staffName($filter)
                    ->clientId($filter);
            })
            ->when(! $request->user()->isOwner(), function ($q) use ($request) {
                return $q->ownedByUser($request->user());
            });

        return [$query, $query->count()];
    }

    /**
     * Get the paginated results for the view.
     *
     * @param $query
     * @param $take
     * @param $paginationPage
     * @return mixed
     */
    private function getPaginationData($query, $take, $paginationPage)
    {
        return $query->orderBy('service_date', 'desc')
            ->take($take)
            ->skip(($paginationPage * $take) - $take)
            ->get();
    }
}

Drfraker left a reply on Multiple Variables Returned With Axios In Vue

axios.get('url/to/route').then((res) => {
    this.object1 = res.data.object1
    this.object2 = res.data.object2
})

07 Jan
8 months ago

Drfraker left a reply on Custom Error Message

[
            "cover_letter.max" => 'Maksimal 500 karakter', 
            "zip.integer" => 'Kode zip harus angka',            
        ]

Drfraker left a reply on Multiple Variables Returned With Axios In Vue

//controller code
return response()->json(['object1' => ['one', 'two'], 'object2' => ['three', 'four']]);

https://laravel.com/docs/5.7/responses#json-responses

04 Jan
8 months ago

Drfraker left a reply on Best Way To Validate Range In Laravel?

You can easily use a custom rule for this use case: run php artisan make:rule ValidAmount

Rule Code:

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidAmount implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return $value >= 0 && $value <= 999;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must be between 0 and 999.';
    }
}

Use in controller:

use App\Rules\ValidAmount;

$request->validate([
    'field' => [new ValidAmount],
]);

11 Dec
9 months ago

Drfraker left a reply on Select Query Posts With Likes

This topic is covered from inception to implementation on the "build a forum" series.

You might want to review the series, starting with this episode https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/18 to get a feel how @jeffreyway did this.

On the forum series it is called a "favorite" instead of a "like" but the concept is the same.