fylzero

fylzero

Member Since 6 Years Ago

Chicago, IL

Experience Points
260,710
Total
Experience

0 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
1786
Lessons
Completed
Best Reply Awards
117
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 50
260,710 XP
Oct
17
3 days ago
Activity icon

Awarded Best Reply on Is It Possible To Extend The Functionality Of The IsProduction Check When Running Migrations?

Found the answer here: https://stackoverflow.com/questions/45938615/custom-laravel-migration-command-illuminate-database-migrations-migrationrepos/45977528#45977528

I basically needed to add the following to my AppServiceProvider:

public function register()
{
    $this->app->singleton(\Illuminate\Database\Migrations\Migrator::class, function ($app) {
        return $app['migrator'];
    });
}
Activity icon

Replied to Is It Possible To Extend The Functionality Of The IsProduction Check When Running Migrations?

Found the answer here: https://stackoverflow.com/questions/45938615/custom-laravel-migration-command-illuminate-database-migrations-migrationrepos/45977528#45977528

I basically needed to add the following to my AppServiceProvider:

public function register()
{
    $this->app->singleton(\Illuminate\Database\Migrations\Migrator::class, function ($app) {
        return $app['migrator'];
    });
}
Activity icon

Replied to Is It Possible To Extend The Functionality Of The IsProduction Check When Running Migrations?

In a perfect world I'd like to be able to extend the functionality of the vendor/laravel/framework/src/Illuminate/Console/ConfirmableTrait.php but I can't think of how that would be possible.

Activity icon

Replied to Deploy To Digitalocean On Push To Github

@lemmon Ok, so your actual question is "are there alternatives to Envoy for Windows?"... because Forge is kind of a different thing.

ServerPilot would be an alternative to Forge, but doesn't do much in the way of deployment.

If you just want deployment for free, you could always just put together a bash script that deploys your code (does Windows do bash? lol idk).

That said, I'd highly recommend just biting the bullet and paying for Forge. Makes life much easier and you can justify the cost as it gives you free SSH certs for all your sites.

OR! Install VirtualBox, run Linux and use Envoy with a shared directory just for deployments. ...or better yet, just over-write Windows with Linux! =) TBH, I'm actually not totally kidding. Once you start needing to manage servers, dev'ing on Windows gets cumbersome imo.

Activity icon

Started a new Conversation Is It Possible To Extend The Functionality Of The IsProduction Check When Running Migrations?

I'm looking at:

vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php

...and want to extend the functionality of the if (! $this->confirmToProceed()) { check where it looks for "production" and warns against running migrations.

My initial attempt was to create a command called SafeMigrateComment and extend the MigrateCommand but I run into the following when trying to do so...

Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable while building [App\Console\Commands\SafeMigrateCommand, Illuminate\Database\Migrations\Migrator].

Any thoughts on how I can add logic here?

Here is my SafeMigrationCommand right now:

<?php

namespace App\Console\Commands;

use Illuminate\Database\Console\Migrations\MigrateCommand;

class SafeMigrateCommand extends MigrateCommand
{
    protected function additionalMethod()
    {
        dd('testing123');
    }
}

Full error I am seeing:

   Illuminate\Contracts\Container\BindingResolutionException

  Target [Illuminate\Database\Migrations\MigrationRepositoryInterface] is not instantiable while building [App\Console\Commands\SafeMigrateCommand, Illuminate\Database\Migrations\Migrator].

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:1017
    1013▕         } else {
    1014▕             $message = "Target [$concrete] is not instantiable.";
    1015▕         }
    1016▕
  ➜ 1017▕         throw new BindingResolutionException($message);
    1018▕     }
    1019▕
    1020▕     /**
    1021▕      * Throw an exception for an unresolvable primitive.

      +25 vendor frames
  26  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Activity icon

Replied to Deploy To Digitalocean On Push To Github

@lemmon What do you mean "alternatives to Forge for Windows". Forge is an outboard server management panel that runs as a web application. If you're running Windows as your development machine, you can still deploy code to your servers using Forge, no problem.

Oct
01
2 weeks ago
Activity icon

Replied to CURL Domain Name Not Found Valet

Having this same problem. I was able to solve by adding my api test address to /etc/hosts

127.0.0.1		myapicode.test

Feels really ugly to have to do this though. Also, if you use Valet secure, that won't work either. I'm trying with the Laravel Http client (Guzzle wrapper) and it complains if I have SSL turned on in Valet. Kinda wish these played nice together. I'm still digging to see if there's a better answer.

I decided to open an issue with the Valet team if anyone wants to follow...

https://github.com/laravel/valet/issues/983

Sep
26
3 weeks ago
Activity icon

Awarded Best Reply on Laravel Not Using The MAIL_FROM_NAME When Sending Emails (on Forge)

I figured it out. Turned out I was using ->from('[email protected]')... which overrides the global default.

Fun fact: If you do ->from('[email protected]', 'Name') that works.

Activity icon

Replied to Laravel Not Using The MAIL_FROM_NAME When Sending Emails (on Forge)

I figured it out. Turned out I was using ->from('[email protected]')... which overrides the global default.

Fun fact: If you do ->from('[email protected]', 'Name') that works.

Activity icon

Started a new Conversation Laravel Not Using The MAIL_FROM_NAME When Sending Emails (on Forge)

A Laravel application I host on Forge and for some reason the emails aren't sending with the MAIL_FROM_NAME. Can't figure out why so far. Anyone run into this?

Sep
17
1 month ago
Activity icon

Replied to Guidance On Laravel 8 Exception Handler

Anyone? Anyone? Bueller? =)

Sep
14
1 month ago
Activity icon

Replied to AddEventListener Not Working? Using Exact Example From Cashier.

@cportal31 That is a pretty outdated practice tbh. You should avoid doing that and just place your script tags below your DOM. I'm also not a fan of the defer tag because it causes a page flicker issue in Bootstrap.

Sep
13
1 month ago
Activity icon

Commented on Squash A Massive Migrations Folder

I can look into it at some point but I'm curious, does anyone know if this exports the current schema from the database itself? ...or is the schema generated from the migration files?

Activity icon

Started a new Conversation Guidance On Laravel 8 Exception Handler

I'm a little unclear how to make this work. In Laravel 7 I used the report method and would send all exceptions to a Slack log. Then just add ones I didn't want to see to the $dontReport array.

The new Laravel 8 setup has just a register method and I'm not sure how to use this, even after reading the docs. I tried just adding the old methods from Laravel 7 and they will report everything and ignore the $dontReport array, which is not tenable.

How can I report all exceptions to Slack and add ones I don't want to be reported in a way that works? I'd like to do things the preferred Laravel 8 way, if possible.

Sep
12
1 month ago
Activity icon

Replied to Trouble With Eloquent And DISTINCT

@spikerok Your suggestion lead to my answer! Thanks! I removed the select, joins and distinct and just walked everything down using with() relationships.

Still a WIP but here's the top section I changed for anyone interested...


        $tickets = Ticket::with(['location', 'customer', 'status']);

        // Filter: Search Term - Ticket Issue & All Comments
        if ($request->is('ticket*') && $request->filled('search')) {
            $searchedWords = collect(explode(' ', $request->search));

            $searchedWords->each(function ($searchedWord) use ($tickets) {
                $tickets = $tickets->where('issue', 'like', '%'.$searchedWord.'%');

                $tickets = $tickets->orWhereHas('comments', function (Builder $query) use ($searchedWord) {
                    $query->where('comment', 'like', '%'.$searchedWord.'%');
                });
            });
        }

I was for sure over-engineering this problem. This was really old code I was refactoring, I was just hesitant to fully bring it over to the Eloquent way as I'm still learning more of the intermediate features of it.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@spikerok I like the refactor suggestions. For sure this can be simplified. Just doing things long-form for troubleshooting before refactoring but I will definitely employ that mapping suggestion in some fashion.

I'm not sure how to get the fuzzy search on issues and comments working if relationships are added in Eloquent but I'll try to think through that a bit.

I ultimately may just scrap some of this and move towards an Algolia implementation if this gives me too much more of a headache.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@sinnbeck I've never touched xdebug, I wouldn't know where to start with that.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@frankielee I understand but look closely at what I am doing. I am left joining a comments table and searching comments which will match and create additional entries which will cause duplicate tickets.id rows. Thus, I am selecting distinct on the id column to remove those duplicates made by the left-joined search-matched comments. Again, this SQL output works perfectly fine in TablePlus. ...I'm completely lost on why this doesn't work as expected when it hits the $tickets = $tickets->get(); line.

If I dd($tickets->count()) before that line, it results in 4.

If I dd($tickets->count()) after that line, it results in 5.

That's pretty messed up.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@spikerok I was just mentioning that I'm not using groupBy as I've heard/read that has issues when using distinct. Just didn't want anyone spinning their wheels asking if that was part of the equation.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@frankielee That solution isn't solving the issue for me unfortunately.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

Here's the whole sql method...


    /**
     * Converting ticket SQL to Eloquent/QueryBuilder magic
     * Hopefully this works  =T
     *
     * @param  search:term  - Search term for deep searching issues and comments
     * @param  billable:bool  - Filters billable tickets
     * @param  assigned:id  - Filters tickets by ticket assignee id
     * @param  closed:bool  - Filters closed tickets
     * @param  all:bool  - Removes filters for opened, closed, on-hold, etc.
     * @param  department:id  - Filters tickets by location department id
     * @param  customer:id  - Filters tickets by location customer id
     * @param  location:id  - Filters tickets by location id
     * @param  opener:id  - Filters tickets by ticket created_by id
     * @param  closer:id  - Filters tickets by ticket closed_by id
     * @param  action:open|closed  - Filters tickets closed/not-closed betweem dates
     * @param  from:datestamp
     * @param  to:datestamp
     * @param  sort:assignee|status|date
     */
    public function sql(Request $request)
    {
        $tickets = Ticket::query();
        $tickets = $tickets->select(
            'tickets.id',
            'tickets.location_id',
            'tickets.status_id',
            'tickets.assignee_id',
            'tickets.issue',
            'tickets.weekend',
            'tickets.after_hours',
            'tickets.billable',
            'tickets.billed',
            'tickets.created_by',
            'tickets.created_at',
            'tickets.closed_by',
            'tickets.closed_at',
            'locations.customer_id',
            'locations.label',
            'ticket_statuses.id as status_id',
            'customers.name'
        );
        $tickets = $tickets->leftJoin('locations', 'locations.id', '=', 'tickets.location_id');
        $tickets = $tickets->leftJoin('customers', 'customers.id', '=', 'locations.customer_id');
        $tickets = $tickets->leftJoin('ticket_statuses', 'ticket_statuses.id', '=', 'tickets.status_id');

        // Filter: Search Term - Ticket Issue & All Comments
        if ($request->is('ticket*') && $request->filled('search')) {
            $tickets = $tickets->addSelect('comments.commentable_id', 'comments.commentable_type', 'comments.comment');
            $tickets = $tickets->leftJoin('comments', function ($join) {
                $join->on('tickets.id', '=', 'comments.commentable_id')
                    ->where('comments.commentable_type', '=', 'App\Models\Ticket');
            });

            $searchedWords = collect(explode(' ', $request->search));

            $searchedWords->each(function ($searchedWord) use ($tickets) {
                $tickets = $tickets->where(function ($query) use ($searchedWord) {
                    $query->where('tickets.issue', 'like', '%'.$searchedWord.'%');
                    $query->orWhere('comments.comment', 'like', '%'.$searchedWord.'%');
                });
            });
        }

        // Filter: Billable
        if ($request->is('ticket*') && $request->filled('billable')) {
            $tickets = $tickets->billable();
        }

        // Filter: Assigned to user
        if ($request->is('ticket*') && $request->filled('assigned')) {
            $tickets = $tickets->where('tickets.assignee_id', $request->assigned);
        }

        // Filter: Closed
        if ($request->is('ticket*') && $request->scope == 'closed') {
            $tickets = $tickets->closed();
        }

        // Filter: All or Not-Closed (Default)
        if ((!$request->scope == 'all') || ($request->scope == 'open')) {
            $tickets = $tickets->notClosed();
        }

        // Filter: Department
        if ($request->is('ticket*') && $request->filled('department')) {
            $tickets = $tickets->whereHas('location', function (Builder $query) use ($request) {
                $query->where('locations.department_id', $request->department);
            });
        }

        // Filter: Customer
        if ($request->is('ticket*') && $request->filled('customer')) {
            $tickets = $tickets->whereHas('location', function (Builder $query) use ($request) {
                $query->where('locations.customer_id', $request->customer);
            });
        }

        // Filter: Location
        if ($request->is('ticket*') && $request->filled('location')) {
            $tickets = $tickets->where('tickets.location_id', $request->location);
        }

        // Filter: Opened By & Closed By
        if ($request->is('ticket*') && $request->filled('opener')) {
            $tickets = $tickets->where('tickets.created_by', $request->opener);
        }
        if ($request->is('ticket*') && $request->filled('closer')) {
            $tickets = $tickets->where('tickets.closed_by', $request->closer);
        }

        /**
         * Filter: Date Range
         * @param  scope  - all, opened, closed
         * @param  from  - 2020-01-01
         * @param  to  - 2022-03-31
         */
        if ($request->is('ticket*') && ($request->filled('from') || $request->filled('to'))) {
            // Default to waaay in the past
            $from = now()->subYears(500)->toDateTimeString();
            if ($request->from) {
                $from = Carbon::parse($request->from, auth()->user()->settings->timezone)
                    ->startOfDay()->timezone('UTC')->toDateTimeString();
            }
            // Default to waaay in the future
            // Theory being, nothing can happen before "now" anyways
            $to = now()->addYears(500)->toDateTimeString();
            if ($request->to) {
                $to = Carbon::parse($request->to, auth()->user()->settings->timezone)
                    ->endOfDay()->timezone('UTC')->toDateTimeString();
            }
            if ((in_array($request->scope, ['all', 'open'])) && (!$request->has('closer'))) {
                $tickets = $tickets->whereBetween('tickets.created_at', [$from, $to]);
            }
            if (($request->scope == 'closed') || $request->has('closer')) {
                $tickets = $tickets->whereBetween('tickets.closed_at', [$from, $to]);
            }
        }

        // Ignore hidden locations
        $tickets = $tickets->whereHas('location', function (Builder $query) {
            $query->where('locations.hidden', false);
        });

        // Clear multiple results if searching because of comment left join
        if ($request->is('ticket*') && $request->filled('search')) {
            $tickets = $tickets->distinct('tickets.id');
        }

        /**
         * Sort
         * @param  sort  - assignee, date, status
         * @param  scope  - closed
         */
        if ($request->is('ticket*') && $request->scope == 'closed') {
            $tickets = $tickets->orderByDesc('tickets.closed_at');
        }
        $sort = $request->sort ?: auth()->user()->settings->tix_sort;
        if ($request->is('ticket*') && $sort == 'assignee') {
            $tickets = $tickets->orderByDesc('tickets.assignee_id')
                ->orderBy('ticket_statuses.priority')
                ->orderByDesc('tickets.created_at');
        }
        if ($request->is('ticket*') && $sort == 'status') {
            $tickets = $tickets->orderBy('ticket_statuses.priority')
                ->orderByDesc('tickets.created_at');
        }
        if ($request->is('ticket*') && $sort == 'date') {
            $tickets = $tickets->orderByDesc('tickets.created_at');
        }
        $tickets = $tickets->orderBy('customers.name');

        // dd($tickets->toSql());

        return $tickets;
    }

This is the method that calls it...

    /**
     * This is the server-driven-parital that actually shows the ticket list
     */
    public function display(Request $request)
    {
        $tickets = $this->sql($request);

        // Pagination Limit
        if (!$request->page || ($request->page == '1')) {
            $tickets = $tickets->offset(0)->limit(auth()->user()->settings->pagination);
        } else {
            $page = $request->page - 1;
            $page = $page * auth()->user()->settings->pagination;
            $tickets = $tickets->offset($page)->limit(auth()->user()->settings->pagination);
        }

        $tickets = $tickets->get();

        return view('pages.resources.ticket.ticket-display.main', compact('tickets'));
    }

Here is the SQL output...

select
  distinct `tickets`.`id`,
  `tickets`.`location_id`,
  `tickets`.`status_id`,
  `tickets`.`assignee_id`,
  `tickets`.`issue`,
  `tickets`.`weekend`,
  `tickets`.`after_hours`,
  `tickets`.`billable`,
  `tickets`.`billed`,
  `tickets`.`created_by`,
  `tickets`.`created_at`,
  `tickets`.`closed_by`,
  `tickets`.`closed_at`,
  `locations`.`customer_id`,
  `locations`.`label`,
  `ticket_statuses`.`id` as `status_id`,
  `customers`.`name`,
  `comments`.`commentable_id`,
  `comments`.`commentable_type`,
  `comments`.`comment`
from
  `tickets`
  left join `locations` on `locations`.`id` = `tickets`.`location_id`
  left join `customers` on `customers`.`id` = `locations`.`customer_id`
  left join `ticket_statuses` on `ticket_statuses`.`id` = `tickets`.`status_id`
  left join `comments` on `tickets`.`id` = `comments`.`commentable_id`
  and `comments`.`commentable_type` = 'App\Models\Ticket'
where
  (
    `tickets`.`issue` like '%eod%'
    or `comments`.`comment` like '%eod%'
  )
  and `status_id` != 5
  and `tickets`.`created_at` between '2020-09-01 05:00:00'
  and '2020-09-13 04:59:59'
  and exists (
    select
      *
    from
      `locations`
    where
      `tickets`.`location_id` = `locations`.`id`
      and `locations`.`hidden` = 0
  )
order by
  `tickets`.`created_at` desc,
  `customers`.`name` asc
limit
  20 offset 0
Activity icon

Replied to Trouble With Eloquent And DISTINCT

@spikerok I'm not super familiar with using DB::listen and the docs didn't really get me there. I did however install Telescope just to see the final query and it outputs correctly... if I copy/paste the query directly to TablePlus, I get 4 results. Makes zero sense to me why the actual $query->get() is outputting 5 results where one is a duplicate of the id I am asking to be distinct.

Activity icon

Replied to Trouble With Eloquent And DISTINCT

@frankielee Thanks for the reply. Gave it a shot, no such luck. I also am passing the column I am trying to be distinct, which is a table id into the distinct call. $query->distinct('table.id'). It's so odd that it counts and I get correct results with the query it spits out, but get() seems to throw a monkey wrench into the gears. I don't get why.

Activity icon

Started a new Conversation Trouble With Eloquent And DISTINCT

This one is really messing with me. I have a VERY complex Eloquent call. Everything works great / properly but for some reason while I am using distinct... it flat out doesn't work and returns multiple results. Here's the messed up part...

When I $query->toSql() and bring the statement over to TablePlus and run the SQL statement, distinct works.

When I run the Eloquent call with $query->count() I get 4 results, which is what I expect from using distinct.

BUT, when I run the Eloquent call with $query->get() I get 5 results because distinct is ignored!!!

I am not using groupBy AT ALL. Happy to provide code but it is a VERY long / complex call.

Sep
09
1 month ago
Activity icon

Awarded Best Reply on Naming For Eloquent Relationship

@lekax I would maybe just call the hasMany relation ownedPredictionGames().

Sep
08
1 month ago
Activity icon

Replied to Naming For Eloquent Relationship

@lekax I would maybe just call the hasMany relation ownedPredictionGames().

Aug
30
1 month ago
Activity icon

Replied to Trap SMS (Nexmo) Notifications When Running Local Dev Environment

@piljac1 Thanks!

This is where I landed... just fired them to Slack if local.

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return app()->isLocal() ? 'slack' : 'nexmo';
    }

    /**
     * Get the Nexmo / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toNexmo($notifiable)
    {
        return (new NexmoMessage)->content($this->message);
    }

    /**
     * Get the Slack representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return SlackMessage
     */
    public function toSlack($notifiable)
    {
        return (new SlackMessage)->to('#sms')->content($this->message);
    }
Aug
29
1 month ago
Activity icon

Started a new Conversation Trap SMS (Nexmo) Notifications When Running Local Dev Environment

I'm wondering if anyone has a good pattern or way to do something similar to what Mailtrap or Helo do for emails but for SMS notifications?

I use Nexmo with Laravel notifications and don't want text messages getting send out and ideally I'd like to log them in a way that I can see they are being sent and the content of the messages when working locally.

I'm sure I can figure out a way to do this but wondered if anyone has anything solid they've done to handle this.

Thanks in advance!

Aug
25
1 month ago
Activity icon

Awarded Best Reply on Google Recaptcha For User Registration?

@astro_369 Maybe I am misunderstanding but the validation piece is what blocks invalid captcha from getting through. Skipping that would defeat the entire purpose.

Aug
20
2 months ago
Activity icon

Replied to Mix/split Vue Components Into Separate Final Js Files.

@guntarv A js file is arguably "too big" at around 6-9mb imo. That falls around the average payload of a Wordpress site these days but there aren't any rules around this. If you have a large js file, you can always put a load screen with some animation that will only take as long as it does on first load because browser cache. I've written some pretty massive Vue applications and js file size has never been a real issue.

Activity icon

Awarded Best Reply on Approach For Testing A Multi-tenant App.

@rachids You could just shift your tests to use mysql. It is slower but there is an argument to be made for this case and also aligning to test against the exact same db you use in prod.

Aug
18
2 months ago
Activity icon

Awarded Best Reply on Mix/split Vue Components Into Separate Final Js Files.

@guntarv I would generally advise not to do this as it is more work than it is worth for such a small optimization. That said, you could just create a copy of app.js to admin.js and add the extra file to your webpack config.

Activity icon

Replied to Sanctum & Personal Access Tokens

@daniti Are you hitting web routes or API routes? Your API routes shouldn't require CSRF.

Activity icon

Replied to Structuring Js Files

@bkuhl I feel like I've seen this question pop up a few times lately. Using the single file approach is generally faster. It loads one time and is cached. How slow is the initial file load to justify such an optimization? Unless your compiled js file is pushing like 5mb+, I wouldn't bother.

That said you can create as many compiled js files as you'd like using the webpack.config.js file at the front of your project.

Vue just needs to be pulled in and reference your #app or whatever to instantiate itself.

Activity icon

Replied to Laravel Package Illuminate/support Version Constraint

@ejunker I feel your frustration. I have had to harass so many package managers to update their Laravel constraint in composer.json it isn't even funny. That said, this is usually limited so the package developer can explicitly test and/or support specific versions. I'm not sure what the best practice is but I'd sure wish when each new version of Laravel came out that I wasn't stuck having to bother adding issues to 4 or 5 repos everytime.

In general, I agree they should just say if it is over version 6, good enough.

Activity icon

Replied to Linting And Beautifying With Sublime

@jukka Use VS Code. I know Microsoft sucks but they actually got this one right. There is a reason it is the most widely adopted "IDE" currently.

Activity icon

Replied to Auto Authenticate When Request Sent From One Project To Another Project.

@ravish Google Laravel SSO or Single-Sign On. That should get you where you want to be.

Activity icon

Replied to Storing JWT Token Lumen

@handisb The JWT would be stored client side in a cookie/not on the server (Lumen). Once you have the token client side you'll want to pass the Bearer token into the headers of whatever you are using to make data calls. Maybe Axios, for example.

Activity icon

Replied to Mix/split Vue Components Into Separate Final Js Files.

@guntarv I would generally advise not to do this as it is more work than it is worth for such a small optimization. That said, you could just create a copy of app.js to admin.js and add the extra file to your webpack config.

Activity icon

Replied to Approach For Testing A Multi-tenant App.

@rachids You could just shift your tests to use mysql. It is slower but there is an argument to be made for this case and also aligning to test against the exact same db you use in prod.

Activity icon

Replied to Google Recaptcha For User Registration?

@astro_369 Maybe I am misunderstanding but the validation piece is what blocks invalid captcha from getting through. Skipping that would defeat the entire purpose.

Activity icon

Replied to Create Method Does Not Exist Error Even Its On The Controller

@rushand Try running php artisan optimize:clear then see if it works. Shouldn't have to but worth a shot.

Jul
22
2 months ago
Activity icon

Replied to Is It Possible To "join" Two Collections Based On A Key?

@michaloravec I've tested both of your suggestions and if I add a 4th entry to $col2 for example...

[
    'id' => 4,
    'name' => 'James',
    'status_slug' => 'merp',
    'secret' => '67890',
],

Both of the code blocks you provided truncate the last entry. The one I posted seems to work.

Also, I do not believe I have any mistakes. My code is working. The last block you posted does not work. Try testing these, you'll see.

I'm basically just thinking about this as a way to replace a lookup table join on enums, if that helps.

Activity icon

Replied to Is It Possible To "join" Two Collections Based On A Key?

@michaloravec Apologize for not being clear here... suffice it to say I knew I needed to map on $col2 for this to work the way I needed. Your answer got me pretty close. I basically wanted this to act like a "left join" not only a single matched result. What I was seeing by adding more data in $col2 before is that it would only match a single result then ignore the rest if there were multiple entries with the same slug. By mapping on $col2 and matching against each label in $col1 this gives the result I was seeking.

Activity icon

Replied to Is It Possible To "join" Two Collections Based On A Key?

@michaloravec Appreciate the reply! Only thing is that this approach seems to fall apart once more data is added to $col2. I'm still playing around with it but struggling to get this to work in a flexible way. If you have any other suggestion, please let me know. Thanks again.

Update: Your answer lead me here...

$result = $col2->map(function ($user) use ($col1) {
    foreach ($col1 as $label) {
        if ($user['status_slug'] == $label['slug']) {
            return $user + $label;
        }
    }
});
Jul
21
2 months ago
Activity icon

Started a new Conversation Is It Possible To "join" Two Collections Based On A Key?

Is it possible to take this...

$col1 = collect([
    [
        'slug' => 'merp',
        'label' => 'Merp',
        'desc' => 'Merp of merp',
    ],
    [
        'slug' => 'derp',
        'label' => 'Derp',
        'desc' => 'Derp derpington',
    ],
    [
        'slug' => 'whoa',
        'label' => 'Whoa There',
        'desc' => 'Hang on just a second',
    ],
]);

...and this...

$col2 = collect([
    [
        'id' => 1,
        'name' => 'Steve',
        'status_slug' => 'merp',
        'secret' => '12345',
    ],
    [
        'id' => 2,
        'name' => 'Joe',
        'status_slug' => 'derp',
        'secret' => '67890',
    ],
]);

...and have the end result be this...

=> Illuminate\Support\Collection {
     all: [
        [
            "id" => 1,
            "name" => "Steve",
            "status_slug" => "merp", // matched on slug
            "secret" => "12345",
            "slug" => "merp", // matched on status_slug
            "label" => "Merp",
            "desc" => "Merp of merp",
        ],
        [
            "id" => 2,
            "name" => "Joe",
            "status_slug" => "derp", // matched on slug
            "secret" => "67890",
            "slug" => "derp", // matched on status_slug
            "label" => "Derp",
            "desc" => "Derp derpington",
        ],
    ],
   }

I'd assume I can just map or each this somehow but am struggling to get there.

Jul
01
3 months ago
Activity icon

Replied to Is It Possible To Cache An Eloquent Call... Then Paginate On That?

@jlrdw I landed on kind of a hybrid solution code-wise...

$customersCache = Cache::remember('locations', 3600, function () {
    return Customer::whereHas('locations', function ($query) {
        return $query->where('hidden', false);
    })
    ->with('locations')
    ->orderBy('customer_name')->get();
});

$page = $request->input('page', 1);
$perPage = 20;
$customers = new LengthAwarePaginator(
    $customersCache->forPage($page, $perPage),
    $customersCache->count(),
    $perPage,
    $page
);

return view('customers', compact('customers'));

Pagination links... this is weird to me why this injects slashes / can't work the normal way.

{!! str_replace('/?', '?', $customers->withQueryString()->links()) !!}
Activity icon

Replied to Is It Possible To Cache An Eloquent Call... Then Paginate On That?

@jlrdw I can admit when I'm wrong. Your last solution on that page DOES TOTALLY WORK! Nice!!!

Follow up (5 minutes later): This is excellent! It's a crazy solve but this is flying now! Perfect!

Thank you for this.