fylzero

fylzero

Member Since 6 Years Ago

Chicago, IL

Experience Points
242,540
Total
Experience

2,460 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
1683
Lessons
Completed
Best Reply Awards
108
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 49
242,540 XP
May
31
18 hours ago
Activity icon

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

@mikylucky You basically just need to make sure your app.js file loads before this code is executed so the Stripe/Cashier js loads first. By default Laravel adds a defer to the Javascript tag in the layout view.

<script src="{{ asset('js/app.js') }}" defer></script>

Basically what defer is doing is the same as placing the script tag before the closing body tag, which is a common practice but also requires using a DOM ready check like this...

$(function () {
    // Javascript code to run after DOM is loaded here
});

I think basically all I did was rip out the defer tag and it worked.

<script src="{{ asset('js/app.js') }}"></script>

This probably happened because I was using a script tag and yielding it into the blade template. I can't remember exactly. I was doing that to avoid having this code load everywhere.

It probably wouldn't hurt anything to leave defer as is and just add this to your compiled Javascript either. I'm assuming it just wouldn't add the listener if it couldn't find the #card-element on the page. Both approaches feel muddy. I think I opted for the first approach as js is cached once it is loaded anyways, so I didn't mind the tiny slow down there. I also felt it was better not to load the Stripe code on all pages.

May
30
1 day ago
Activity icon

Awarded Best Reply on If You Are Testing With Dusk, Do You Need To Also Test With Jest?

I've been continuing some light research and have generally come to the conclusion that Jest is best suited for unit testing javascript and Dusk is more for feature (wide) testing any front end structure you have (since it is essentially a browser test).

Activity icon

Replied to If You Are Testing With Dusk, Do You Need To Also Test With Jest?

I've been continuing some light research and have generally come to the conclusion that Jest is best suited for unit testing javascript and Dusk is more for feature (wide) testing any front end structure you have (since it is essentially a browser test).

May
29
2 days ago
Activity icon

Replied to What Is Your Opinion On Using != Vs !== In PHP? SQLite Testing

I eventually learned that using $casts in models largely solves this problem. By type-casting data it is usable with any database and solidifies your data types called from Eloquent.

May
24
1 week ago
Activity icon

Awarded Best Reply on Search With Date Picker And Show Result

@itrabbi24 Using a date picker is pretty well documented in Javascript land. If you need something simple for Bootstrap, check out jQuery UI. https://jqueryui.com/datepicker/

Beyond that, when handling date searching Laravel makes it super easy. Laravel has Carbon built in, so it is very easy to do Carbon::parse($start_date)->toDateTimeString(), etc. on your date objects and pass that to your queries.

Even easier if you use Eloquent, but with Querybuilder just use those strings in your query.

Activity icon

Replied to Email Hosting

@morganc3 Pro tip, if you want to do this for free... transfer your domains to Google Domains and use email aliases.

Amazing trick: https://support.google.com/domains/answer/9437157

I've been doing this for smaller apps and it works great.

Otherwise pay for a Hover or Gmail G Suite account... if this is just for transactional email, consider using AWS SES.

Also, you can just use Gmail too. Just allow third-party sending in the security settings, enable IMAP/POP and plug smtp.gmail.com:465 into your apps.

Activity icon

Replied to Search With Date Picker And Show Result

@itrabbi24 Using a date picker is pretty well documented in Javascript land. If you need something simple for Bootstrap, check out jQuery UI. https://jqueryui.com/datepicker/

Beyond that, when handling date searching Laravel makes it super easy. Laravel has Carbon built in, so it is very easy to do Carbon::parse($start_date)->toDateTimeString(), etc. on your date objects and pass that to your queries.

Even easier if you use Eloquent, but with Querybuilder just use those strings in your query.

Activity icon

Replied to How To Get Middleware To Fire?

@konarktriv7 I would argue that what you are trying to do is kind of leaning into the "testing the framework" and "unhappy path" approach. Which you really shouldn't need to do.

That said... is this kind of what you're looking for?

$response = $this->get('/route');
$response->assertForbidden();
Activity icon

Replied to Use Different Method Name For Polymorphic Relationship

@ehsanm Try running composer dump-autoload or maybe php artisan optimize:clear. Seems like something is holding onto the file if it is still saying the model is referencing image instead of img.

Either that or you are calling that relationship image somewhere. Look at your stack trace to figure out where if that's the case. You could also possibly be referencing the attribute as Category::first()->image() instead of Category::first()->image, just make sure if you are referencing the accessor attribute you don't use parentheses after it. I'm pretty sure that might give you this error as well.

Activity icon

Replied to Use Different Method Name For Polymorphic Relationship

@ehsanm Yes, this is possible. I just tested with a polymorphic implementation I use. You can change the method name for your polymorphic relationship so long as you refer to it as that in your relationships throughout the app.

May
23
1 week ago
Activity icon

Replied to Use A Different View On / Route When Logged In Vs. Logged Out

@siangboon Thanks for your reply. That wouldn't solve my full problem. What I posted was the only way I could think to do this.

Basically wanted...

Logged out -> Go to home route -> displays home view.

Logged in -> Go to home route -> displays app view.

Removing auth middleware would stop the redirection but would not let me split this route/view pathing the way I wanted.

Activity icon

Awarded Best Reply on Use A Different View On / Route When Logged In Vs. Logged Out

Ok, ok, ok... here's the solution.

Route::get('/', 'HomeController');
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function __invoke()
    {
        if (auth()->check()) {
            return view('app.dashboard');
        }

        return view('website.home');
    }
}

I could not get this to work purely in the routes file but this does what I wanted.

Activity icon

Replied to Use A Different View On / Route When Logged In Vs. Logged Out

Ok, ok, ok... here's the solution.

Route::get('/', 'HomeController');
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    public function __invoke()
    {
        if (auth()->check()) {
            return view('app.dashboard');
        }

        return view('website.home');
    }
}

I could not get this to work purely in the routes file but this does what I wanted.

Activity icon

Replied to Use A Different View On / Route When Logged In Vs. Logged Out

app/Http/Middleware/Authenticate.php is redirecting me to login assuming the last route for / is what I'm trying to do and since it is in auth middleware, it is asking me to login. Cool, got that. Now how do I get around this?

I tried slapping guest middleware on the logged out route...

Route::view('/', 'home')->middleware('guest');

...that isn't working.

I've tried wrapping in an auth check.

...that doesn't work.

I tried an auth check outside the auth middleware altogther.

...nope!

Activity icon

Started a new Conversation Use A Different View On / Route When Logged In Vs. Logged Out

I feel like I've fought this issue and lost or won several times now but it is not intuitive to me.

Simply put, I want to display a home.blade.php on the root of my URL whatever.test aka / when I am logged out. Then, I want to display a app.blade.php on the root of my URL whatever.test aka / when I am logged in.

Whenever I set this up, if I go to / when logged out, I get redirected to the /login page?!

Route::view('/', 'home');
Auth::routes(['verify' => true]);

Route::middleware('auth')->group(function () {
    Route::view('/', 'app');
});

What am I missing here?

May
22
1 week ago
Activity icon

Awarded Best Reply on Global Scope On User Model Not Working.

Figured this out... just needed to pass the auth user into the scope and it started working. Also had to isset check the user so registration wouldn't die.

protected static function booted()
{
    $authUser = auth()->user()->company_id ?? null;
    static::addGlobalScope(new CompanyScope($authUser));
}

Found the answer here: https://github.com/laravel/framework/issues/25611

Activity icon

Replied to Global Scope On User Model Not Working.

Figured this out... just needed to pass the auth user into the scope and it started working. Also had to isset check the user so registration wouldn't die.

protected static function booted()
{
    $authUser = auth()->user()->company_id ?? null;
    static::addGlobalScope(new CompanyScope($authUser));
}

Found the answer here: https://github.com/laravel/framework/issues/25611

Activity icon

Replied to Global Scope On User Model Not Working.

Based on experimentation, I'm assuming I can't call auth() in the scope / when on the User model, but why?

If I do this, it works as I'd expect...

public function apply(Builder $builder, Model $model)
{
    $builder->where('company_id', 1);
}
Activity icon

Started a new Conversation Global Scope On User Model Not Working.

Trying to implement multi-tenancy using a single db approach. My scope works on everything except when I try to put it on the User model my app blows up. Won't even load. What am I doing wrong here?

CompanyScope...

<?php

namespace App\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class CompanyScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        if (auth()->check()) {
            $builder->where('company_id', auth()->user()->company_id);
        }
    }
}

Code on the user model...

protected static function booted()
{
    static::addGlobalScope(new CompanyScope);
}

I'm just trying to display only users that belong to the current users company_id.

What I'm seeing after adding this...

May
16
2 weeks ago
Activity icon

Replied to Property Or Method Is Not Defined On The Instance But Referenced During Render

@bhalliburton Try changing the name of your method to something else. It has the same name as the component. Not sure if that's the issue but it is where I'd start.

There is a lot going on here that I am not familiar with. Assuming the spark mixing allows you to intermingle blade with vue files?

May
14
2 weeks ago
Activity icon

Started a new Conversation If You Are Testing With Dusk, Do You Need To Also Test With Jest?

I'm wondering if there is strong value in pulling Jest via vue-test-utils into a project?

I haven't done much testing of Javascript and I'm looking for some thoughts and opinions on if pulling Jest into the project is worth the effort or if just doing wide tests on the front end is good enough?

I realize this is a broad question. Feel free to link to useful articles on the subject here as well. Thanks!

May
10
3 weeks ago
Activity icon

Replied to Whoops Something Went Wrong With Nothing In Logs

@kimg I'm assuming you don't see an error because your production .env file has APP_DEBUG=false, as it should BTW.

One thing I like to do in this situation is test and try to reproduce the problem locally with APP_DEBUG=true set in your .env file and see if you can actually look at the error from there.

If it turns out to be a data issue, you can aim your local environment to use your production database and try to reproduce the issue, just be very careful.

Or, lastly, if your production environment isn't heavily used yet and you can get away with it, you could enable APP_DEBUG on prod just to get the error quickly and flip it back... with the caveat that by doing so it could interrupt your users and possibly expose the error / data / etc. to users that shouldn't have it. I've definitely done this before but only if projects didn't have a significant user base yet.

Apr
28
1 month ago
Activity icon

Awarded Best Reply on Vue SPA Authentication Best Practice

@marvinx

New hotness...

https://github.com/laravel/airlock

Passport and using the Axios interceptors listed in this video are hands down the most simple and secure way to secure your Laravel/Vue app imo.

https://laravel.com/docs/6.x/passport

https://www.youtube.com/watch?v=Zv4bUXEwl20

Apr
17
1 month ago
Activity icon

Replied to Event Listener

@davy_yg It means this will only queue the job IF the subtotal is greater than or equal to 5000.

It's called conditional queuing.

Described at the bottom of this section under conditionally queueing listeners. https://laravel.com/docs/master/events#queued-event-listeners

All that code does is return true or false to let the listener know to queue or not.

Apr
16
1 month ago
Activity icon

Replied to Date And Time Getting But Not From By PC

@abdulrafey38 You may find this useful...

https://laravel-news.com/laravel-timezone

I would keep your server time in UTC.

This package will let you automatically save the timezone your users are in. I would give them the ability to change this.

Also, of you just need to display UTC to the local user timezone just use monent js. It does all the work for you.

Activity icon

Replied to Laravel 7 "Class Not Found" With "use" On Top.

@apham5 If you're running VS Code download the extension PHP Namespace Resolver. Then you can use that to import your classes without having to manually type them.

Apr
09
1 month ago
Activity icon

Awarded Best Reply on Wondering Why Uploading Works In Php 7.3, But Not In Php 7.4 With Laravel 6

@ralphmrivera Guzzle will be more reliable but add code complexity. I use file_get_contents sometimes in various apps (similar to fopen)... you just need to know that it can break in certain environments... probably best to use Guzzle.

Apr
05
1 month ago
Activity icon

Replied to Possible To Run Phpunit And Include/exclude More Than One Group?

@bobbybouwmann I thought I tried this... but I had a space after the comma when I tried. 🤦‍♂️

Thank you!

Apr
04
1 month ago
Activity icon

Awarded Best Reply on Forever Plan Badge Is Gone

This was resolved a while back.

Activity icon

Replied to Forever Plan Badge Is Gone

This was resolved a while back.

Activity icon

Awarded Best Reply on What Is Your Opinion On Using != Vs !== In PHP? SQLite Testing

So this actually hasn't been that much of a problem. So far my code and tests run, which I find odd, since SQLite puts out integers as strings and we have strict checking littered throughout the application in question.

I've mostly been able to assertSame and assertEquals instead of strict checking when needed on tests.

Haven't really run into any issues.

Activity icon

Replied to What Is Your Opinion On Using != Vs !== In PHP? SQLite Testing

So this actually hasn't been that much of a problem. So far my code and tests run, which I find odd, since SQLite puts out integers as strings and we have strict checking littered throughout the application in question.

I've mostly been able to assertSame and assertEquals instead of strict checking when needed on tests.

Haven't really run into any issues.

Activity icon

Started a new Conversation Possible To Run Phpunit And Include/exclude More Than One Group?

I have started utilizing the group feature of PHPunit lately and have been trying to see if it is possible to run something like...

Pseudo-syntax being used here:

vendor/big/phpunit --exclude-group foo|bar

Where foo is one group and bar is another group. Basically checking all tests except ones in either group.

Is this possible? How to do this? =)

Mar
19
2 months ago
Activity icon

Awarded Best Reply on Using Models

@randy_johnson You can remove the else statements around your aborts. The else is implicit from the return... write your guards then return the default... like so...

public function delete($slug)
    {
        if (DB::table($this->table)->where('id', '=', $slug)->delete())
        {
            return redirect()->route('read-users');
        } 
      
        return abort(404);

    }

Mar
18
2 months ago
Activity icon

Awarded Best Reply on Asset(mix('css/app.css')) Not Working With HTTPS

I figured this out. Apparently the asset() helper is not solely based on the request but on the APP_URL setting in the .env file. I just needed to update that to APP_URL=https://mysite.test

Activity icon

Replied to Asset(mix('css/app.css')) Not Working With HTTPS

I figured this out. Apparently the asset() helper is not solely based on the request but on the APP_URL setting in the .env file. I just needed to update that to APP_URL=https://mysite.test

Activity icon

Started a new Conversation Asset(mix('css/app.css')) Not Working With HTTPS

Trying to reference assets using this... asset(mix('css/app.css'))

The asset() helper should do what it says in the docs, right?

The asset function generates a URL for an asset using the current scheme of the request (HTTP or HTTPS):

What I am seeing...

Mixed Content: The page at 'https://mysite.test/home' was loaded over HTTPS, but requested an insecure stylesheet 'http://mysite.test/css/app.css'. This request has been blocked; the content must be served over HTTPS.

Why does this happen?

Mar
16
2 months ago
Activity icon

Replied to Policy Method Not Being Called On POST Request

@schtailmuel Your post is hitting storeTags method. Do you have a storeTags method on your JobController?

If you disable your policy, does it work? Just want to make sure it is the policy causing the issue.

class JobPolicy
{
...
    public function update(User $user, Job $job)
    {
        return true;
    }
...
}
Mar
12
2 months ago
Activity icon

Replied to Downsides Of Testing With SQLite?

@stereoh Eh, no one uses that. lol

Activity icon

Replied to Downsides Of Testing With SQLite?

@mabdullahsari In your opinion... is it a bad move to use SQLite for testing? As in, could tests pass that otherwise might not on MySQL?

Activity icon

Started a new Conversation Is It Possible To Run Db:seed When Using SQLite In Memory With Phpunit?

I am using use DatabaseMigrations; in my test files to migrate:fresh the database on every test run.

Is there a way to seed the database on every test?

Activity icon

Started a new Conversation Downsides Of Testing With SQLite?

I'm working on a large scale project with multiple devs and we were discussing the pros and cons of using SQLite :memory: tests.

  • We already know that SQLite does not return integers, which we're wondering if that could cause unexpected issues.
  • The main question that has been raised is, is testing using SQLite "a bad idea" because it is not actually testing what prod runs on? (which is MySQL)

What are your thoughts, opinions, insights? Have you used SQLite for phpunit testing and run into any downsides of doing so?

Mar
11
2 months ago
Activity icon

Replied to What Is Your Opinion On Using != Vs !== In PHP? SQLite Testing

@jlrdw I know the difference. The question is how to approach using SQLite with memory testing since it doesn't support basic type differences?

Activity icon

Started a new Conversation What Is Your Opinion On Using != Vs !== In PHP? SQLite Testing

So, apparently (and correct me if I'm wrong)... All data in SQLite is a string?

I'd like to consider using SQLite :memory: for a project, but said project is using strict type checking in almost every comparison. Not sure if it absolutely needs to be written this way.

What is the best move here?

Don't use SQLite in memory for testing?

Remove the strict comparison operators?

Thanks in advance. Just curious what the room thinks.

Mar
10
2 months ago
Activity icon

Replied to PHPUnit Segmentation Fault On AWS Elastic Beanstalk Deployment (exit Status 139)

@talinon Brilliant! This got us to the bottom of the issue. Thank you!

Activity icon

Replied to How To Update Admin Email In Settings In Dashborad?

@nacha Look in your project folder under config\settings.php you should see entries for default_email_address and site_name . Most likely they should be referencing entries in your .env file in the root of your project. If they reference the .env just put whatever variables the reference in your .env file.

for example...

config\settings.php

'default_email_address' => env('DEFAULT_EMAIL')

.env

[email protected]
Activity icon

Replied to How To Update Admin Email In Settings In Dashborad?

@nacha I really don't have enough information to help you make this call.

What exactly are you trying to accomplish? Can you narrow down your question?

You have a config value, a seeded admin, and Admin model, etc. What exactly are you trying to do/update?

Activity icon

Replied to How To Update Admin Email In Settings In Dashborad?

@nacha Sounds like what you'd want is an Admin model (which you already have) and an AdminController. You can update the Admin email in the database from the update method of the AdminController like so...

$admin = Admin::find(12);
$admin->email = '[email protected]';
$admin->save();

Not sure your use case but I would break admins out of the User model. You could maybe look into using a permission management package like the Spatie package. Because an admin is really a user. Admin is just a user role.

https://github.com/spatie/laravel-permission

I may not fully understand your question but if you are trying to update the config in code you can do...

{{ config(['settings.default_email_address', '[email protected]']) }}
Activity icon

Started a new Conversation PHPUnit Segmentation Fault On AWS Elastic Beanstalk Deployment (exit Status 139)

Wondering if anyone has run into this issue or can help shed some light on what it means.

I'm running a Laravel app on Elastic Beanstalk and executing phpunit on deployment. For some reason, and this was working fine before, but I've started getting a segmentation fault during the phpunit run process. I have been Googling on this for days and can't find even a clue as to what I can do about it.

If anyone has any good information on what this is and/or how to address it, please let me know. Thanks!

[Container] 2020/03/09 22:49:01 Running command vendor/bin/phpunit
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

.........R..............Segmentation fault

[Container] 2020/03/09 22:49:08 Command did not exit successfully vendor/bin/phpunit exit status 139
[Container] 2020/03/09 22:49:08 Phase complete: BUILD State: FAILED
[Container] 2020/03/09 22:49:08 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: vendor/bin/phpunit. Reason: exit status 139
[Container] 2020/03/09 22:49:08 Entering phase POST_BUILD
Mar
01
2 months ago
Activity icon

Awarded Best Reply on Database Relationship With Infinite Depth

Just reference a parent_id for each relationship. Basically if the parent_id is null, it is at the highest level of structure. If a parent_id exists and references the id of another element, then it is the child of that element.

id | parent_id | name
---|-----------|-----
1  | null      | MainFolder
2  | 1         | SubFolder
3  | 2         | SubSubFolder
4  | 3         | SubSubSubFolder
5  | null      | AnotherMainFolder
6  | 5         | SubFolder
7  | 5         | AnotherSubFolder

id can be folder_id and parent_id can be folder_parent_id if that's helpful.