nathangross

nathangross

Front-end Designer at Building 13

Member Since 4 Years Ago

Cincinnati

Experience Points
20,700
Total
Experience

4,300 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
191
Lessons
Completed
Best Reply Awards
1
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 5
20,700 XP
Sep
16
1 week ago
Activity icon

Replied to Get Users From A Collection Of Follows

That worked great!

Activity icon

Started a new Conversation Get Users From A Collection Of Follows

I have a Follow model

    public function location(): BelongsTo
    {
        return $this->belongsTo(Location::class);
    }

    public function sport(): BelongsTo
    {
        return $this->belongsTo(Sport::class);
    }

   public function user(): BelongsTo
   {
       return $this->belongsTo(User::class);
   }

I have a Followable trait with the following method:

public function follows(): HasMany
    {
        return $this->hasMany(Follow::class);
    }

I want to be able to send a notification to everyone who follows a location. I know how to get a collection of follows (which gives me a user_id of each) but how do I get a collection of users from that follows collection?

Sep
12
2 weeks ago
Activity icon

Started a new Conversation How Do You Pass Data Through A Nested Component?

For example, I have a main layout component with some meta tags set up with props. Then I have an additional app layout component nested inside main. How do I pass data through the nested components?

Aug
17
1 month ago
Activity icon

Replied to Polymorphic Trait?

I really appreciate all the help in here—especially from @bobbybouwmann. This is an amazing community.

Ultimately @bugsysha helped talk me through it and I can't thank him enough.

@davidifranco I did end up using a trait for some of the followable methods since I'll have the same "follow" code on several models on my codebase but I take your point about the complexity cost. The complexity will end up somewhere, but I think my problem was trying push the magic of figuring out what model to associate with the follow to a method on the trait—when I think it makes more sense to keep it at the form and controller level.

So for posterity or anyone following along:

My route:

Route::post('/replies/{reply}/favorites', '[email protected]');

My form/view

<form method="POST" action="{{route('follow')}}">
  @csrf
  <input type="hidden" value="App\Event" name="followable_type">
 <input type="hidden" value="{{ $event->id }}" name="followable_id">
 <button type="submit" ">
  Follow
 </button>
</form>

My FollowController:

    public function store(Request $request)
    {
        $attributes = [
            'user_id' => auth()->id(),
            'followable_type' => $request->get('followable_type'),
            'followable_id' => $request->get('followable_id')
        ];

        Follow::query()->firstOrCreate($attributes);
        return back();
    }
Aug
09
1 month ago
Activity icon

Replied to Polymorphic Trait?

If I use the following store method on my FollowController, I get the following error: Call to a member function follow() on string

public function store($model, $id)
{
    $model->follow();

    return back();
}

I think my confusion is just about how all of these files are passing data through to each other and perhaps the order they go in.

So I get that the view is passing the $model (string: event) and an $id (a number) of that event to the controller's store function. The store() method is calling up the follow() method on the Followable trait. But the followable trait is being used by my Event model. From there I have a really hard time grasping what's happening.

Aug
08
1 month ago
Activity icon

Replied to Polymorphic Trait?

The store method is on a controller called FollowController (see below). The way I currently have everything set up:

Follow class

class Follow extends Model
{
    protected $fillable = ['followable_id', 'followable_type', 'user_id'];

    public function followable()
    {
        return $this->morphTo();
    }

Followable trait

trait Followable
{

  public function follows()
  {
    return $this->morphMany(Follow::class, 'followable');
  }


  public function follow()
  {
    $attributes = ['model' => get_class($this), 'model_id' => $this->id, 'user_id' => auth()->id()];
    if (! $this->follows()->where($attributes)->exists()) {
      return $this->follows()->create($attributes);
    }
  }
}

FollowController (this is how I was storing it. But looking to update this store method and utilize the Followable trait—I don't want to have to check the exists logic on the store method)

   public function store($model, $id)
    {
        $attributes = [
            'user_id' => auth()->id(),
            'followable_type' => $model,
            'followable_id' => $id
        ];

        Follow::create($attributes);
        return back();
    }

And a button on a view - could this be improved to make it work on any model (currently Event model)

<form method="POST" action="{{route('follow-event', ['model' => 'event', 'id' => $event->id])}}">
  @csrf
  <button type="submit" >Follow</button>
</form>

I may be a bit confused on if I should create the follow from the user, from the event or somehow from itself and just pass in the model and user attributes.

I hope that all makes sense :)

Aug
07
1 month ago
Activity icon

Replied to Polymorphic Trait?

@bobbybouwmann Ah ok, that makes sense. But now how about on my store method?

Before I was just creating a new Follow instance using Follow::create() and passing in all the attributes from the form. But now that I'm using a new follow() method on a followable trait, I have no idea how to pass that into my store method on my controller.

Before:

public function store($model, $id)
    {

        $attributes = [
            'user_id' => auth()->id(),
            'followable_type' => $model,
            'followable_id' => $id
        ];

        Follow::create($attributes);
        return back();
    }

Now??

public function store($this)
    {
        Follow::create($this);
        return back();
    }

I know that's wrong, but that's how confused I am

Activity icon

Replied to Polymorphic Trait?

Also, I guess I’m not sure on where you guys mean I can use $this

Activity icon

Replied to Polymorphic Trait?

@bobbybouwmann @s4muel Ah I don't think I totally follow. I believe I understand $this refers to the instance of whatever model this trait is applied to. But how do I get $this over to the controller—while keeping both the trait and controller polymorphic and DRY.

This hurts my brain :)

Activity icon

Started a new Conversation Polymorphic Trait?

I am building out a polymorphic (morphMany) class called Follow and a trait called Followable. I'm struggling with getting the right model passed how I'd like.

FWIW I'm semi-following along with Jeffery's Let's build a forum series, episode 18.

So here is where I am currently:

I have Events that can be followed using the Followable trait (and later, other things can be followed, like locations, other users, etc.) Currently, I'm using the following form in an event.show view:

<form method="POST" action="{{route('follow-event', ['model' => 'event', 'id' => $event->id])}}">
  @csrf
   <button type="submit">Follow</button>
</form>

And on my FollowController:

$attributes = [
  'user_id' => auth()->id(),
  'followable_type' => $model,
  'followable_id' => $id
];

Follow::create($attributes);
return back();

AppServiceProvider:

public function boot()
{
  Relation::morphMap([
    'event' => 'App\Event',
  ]);
}

And here is where I'd like to get to:

So far, this all works. But I'm hoping to be able to have a method on my Followable trait to help keep things clean and set some integrity constraints like only 1 follow per event (but keep it polymorphic) per user. Something like:

public function follow($model)
{
  $attributes = ['model' => $model, 'user_id' => auth()->id()];
  
  if (! $this->follows()->where($attributes)->exists()) {
    return $this->follows()->create($attributes);
  };
}

But since this is a trait, I can't figure out a good way to get this method to "understand" what its current class is.

I'd also like to DRY the button on my form so I can reuse it elsewhere. What is a good way to get and pass the model of whatever view it's on?

Aug
05
1 month ago
Activity icon

Replied to Phpstom - Blade Comments

I've unchecked Line comment at first column on both PHP and HTML files. However, this doesn't seem to work for me on Blade files. Unchecking Line comment at first column on other file types like PHP works as expected, but not for Blade .blade.php files.

Is this a known bug perhaps?

Activity icon

Replied to Testing With An Authenticated User

Ah yep—I totally misread the error.

It was due to how my model factory was set up.

Activity icon

Started a new Conversation Testing With An Authenticated User

I'm trying to write a test that needs an authenticated user.

The code in question: $this->actingAs($event->user)

When I run it, I get the following error:

TypeError : Argument 1 passed to Illuminate\Foundation\Testing\TestCase::actingAs() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

My User model:

class User extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;
    use SoftDeletes;
    ...

I'm seeing some other posts that suggest setting the User model to extend Model and use Authenticatable but I don't fully understand what's going on.

What is the best way to set up so I can run tests with an authenticated user?

Thanks!

Activity icon

Replied to (Probably) Overthinking Naming Models And Functions

Yes—some good inspiration from all of his packages. Thanks for sharing @tuneless!

Aug
04
1 month ago
Activity icon

Started a new Conversation (Probably) Overthinking Naming Models And Functions

I'm familiar with the saying that there are only two hard things in computer science: cache invalidation and naming things

As a native English speaker, I'm also familiar with how difficult the language can be at times—in this context, around ambiguous noun/verb words.

I'm building out a "Follow" feature—a feature found in so many social-type sites. Users can follow people, groups, events, etc. to receive updates from those things.

Yet I find myself challenged by naming the class and functions clearly.

Current thinking: Follow model, follows table, Followable trait perhaps.

But I quickly start to anticipate some issues here. Is follows a collection or an action?

I sort of liked the idea of Subscription, subscriptions, subscribe, subscribable due to the clearer nouns and verbs but will probably save those for more billing features later.

Is the solution more verbose naming or better documentation, or something else entirely? I would love some advice on how you have solved these things in your own projects. Links, articles, previous discussion here—any would be welcome.

Thanks!

Jul
28
1 month ago
Activity icon

Replied to Linking Front-end To Edit Resource Instance In Backend (Nova)

Thanks @siangboon

However, I'm using Laravel Nova for a backend so I have not defined those routes. I was hoping Nova offered something similar though.

Activity icon

Replied to Linking Front-end To Edit Resource Instance In Backend (Nova)

This works, but seems a bit heavy handed:

<a href="{{ Nova::path() . '/resources/post/' . $post->id . '/edit' }}">Edit</a>

Curious if there is a better way.

Activity icon

Started a new Conversation Linking Front-end To Edit Resource Instance In Backend (Nova)

Is there a preferred way to handle generating a link to edit the instance of a resource?

For instance, I am on a post show view, and would like to be able to click a link to edit this post in Nova.

Jul
27
2 months ago
Activity icon

Replied to Adding New Seed Data To Existing Project

Thanks for the reply!

Makes sense. I guess I was thinking there might be a type of seeder similar to a migration that adds a column to an existing table.

For this particular use case, I'm using Nova and I need to update my own account with an is_admin value before I can login to Nova and update all the others in prod. I can do it very easy with TablePlus (or similar) but was curious if there was a better practice.

Activity icon

Started a new Conversation Adding New Seed Data To Existing Project

I have an existing project with some users—some coming from an initial UserSeeder file. Now, I've just added roles and permissions to my project. I'd like to programmatically update some user accounts with the new roles/permissions.

What is a good practice here? Would I create a new seeder file? Do I modify my existing UserSeeder file?

Thanks!

Jul
14
2 months ago
Activity icon

Replied to Modifying ShowRegistrationForm()

@bryank Thanks for the reply. I need to pass some additional data to the view.

That showRegistrationForm()method does not exist on app\Http\Controllers\Auth\RegisterController but rather on vendor/laravel/ui/RegisterUsers.php

However, I didn't consider just adding the method to the RegisterController. That does seem to work. I'm assuming that's an ok way to do it?

Activity icon

Started a new Conversation Modifying ShowRegistrationForm()

I'm using Laravel's standard out-of-the-box user authentication. I need to make some changes to the default user registration form—basically pass in some additional data.

Digging in a bit, I see this showRegistrationForm() method in vendor/laravel/ui/RegisterUsers.php.

   public function showRegistrationForm()
    {
        return view('auth.register');
    }

My gut says that's not the best place make modifications, but I'm not sure the best place to do it.

Any advice?

Activity icon

Replied to Structured Data (schema.org) In Markup (SEO)

Adding a link to the site in question for reference: https://matchup.us/cities/cincinnati

Activity icon

Started a new Conversation Structured Data (schema.org) In Markup (SEO)

Not really a Laravel question, but curious if anyone has a good suggestion about using structured data.

Tl;dr: Is it good practice to use structured data in markup for both an index view (excerpts) as well as a show (detail) view?

I have an Event resource (like a sports event with a time and physical location, etc.) with an index view and a detail view. The index view shows a list of excerpts of events. You can click into them to get to an event detail view. Very typical.

My question is, should I be using structured data on both the index view and detail view? I think it's pretty clear that the detail view could benefit for the structured data, but is it necessary (perhaps duplicative) on the index view?

i.e. itemscope itemtype="http://schema.org/Event", itemprop="startDate", itemprop="location"

What prompted this question was the "requirements" for marking up an Event. When you have a location it is looking for a physical address. I don't show the physical address in the index (excerpt) view. But I could include it in the meta data if it is important.

Hopefully that makes sense. Any thoughts?

Jul
12
2 months ago
Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

sports() is nowhere in my entire codebase. I think it has to do with Laravel's assumption that this relationship exists since I'm using RMB with both City and Sport in my route as mentioned in my previous post.

I wonder if there is a way to tell Laravel to ignore that.

Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

In the Laravel Docs: https://laravel.com/docs/7.x/routing#route-model-binding

Custom Keys & Scoping

Sometimes, when implicitly binding multiple Eloquent models in a single route definition, you may wish to scope the second Eloquent model such that it must be a child of the first Eloquent model.

When using a custom keyed implicit binding as a nested route parameter, Laravel will automatically scope the query to retrieve the nested model by its parent using conventions to guess the relationship name on the parent.

I'm pretty sure my error is coming from Laravel assuming that City::sports() relationship exists when it does not. But I'm not sure how I could fix this.

Here is my route: Route::get('/cities/{city:slug}/sports/{sport:slug}', '[email protected]');

Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

@michaloravec I like the idea of using route model binding, so I'd like to figure this out. Any ideas on how to track down why I'm getting this error:

Call to undefined method App\City::sports()

On [email protected]

    public function show(City $city, Sport $sport)
    {
        $events = $sport->events()->whereHas('location.city', function ($query) use ($city) {
            $query->where('slug', $city->slug);
        })->get();

        return view('sport.show', compact('city', 'sport', 'events'));
    }
Jul
11
2 months ago
Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

@michaloravec when I use route model biding like that I get an error looking for (what I believe to be...) the relationship on the model:

Call to undefined method App\City::sports()

Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

Ok, got it now. I was passing in the both the classes (route model binding I think?) and that was throwing me off.

public function show(City $city, Sport $sport) 
{
   ...
}

But here is where I ended up and appears to be working as needed:

    public function show($city, $sport)
    {
        // Get all Events of a Sport in a City
        $events = Event::whereHas('sport', function ($query) use ($sport) {
            $query->where('slug', $sport);
        })->whereHas('location.city', function ($query) use ($city) {
            $query->where('slug', $city);
        })->get(); 

        $city = City::where('slug', '=', $city)->firstOrFail();
        $sport = Sport::where('slug', '=', $sport)->firstOrFail();
        return view('sport.show', ['events' => $events, 'city' => $city, 'sport' => $sport]);
    }

I really appreciate your help @bobbybouwmann as well as @michaloravec too. Thanks!

Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

@michaloravec Ha sorry (perhaps being dense here...), I'm still struggling to get what both relationships should be. If I do the following, I get SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sports.city_id' in 'where clause'

class City extends Model
{
    public function sports()
    {
        return $this->hasMany(Sport::class);
    }
}

class Sport extends Model
{
    public function cities()
    {
        return $this->belongsToMany(City::class);
    }
}
Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

@bobbybouwmann I think I follow that as a query—but just to clarify, what would the relationship for for the City::sport() method?

Activity icon

Replied to Laravel - Defining And Accessing A Distant Relationship

@michaloravec

public function show(City $city, Sport $sport)
    {
        $sport->load('events');
        dd($sport);
        
    }

I've never used load() before. I'll have to look into that.

But this method is looking for City::sports(). How would I define that? (Call to undefined method App\City::sports())

Activity icon

Started a new Conversation Laravel - Defining And Accessing A Distant Relationship

Currently, I have the following Models and relationships: City, Location, Event, Sport

  • Cities have many Locations
  • Locations have many Events
  • Events belong to Sport

Within [email protected] (Route::get('/cities/{city:slug}/sports/{sport:slug}', '[email protected]');)

I'd like to be able to show all Events of a particular Sport in a particular City.

I'm struggling to define the City/Sport relationship. It seems to be beyond hasManyThrough. Is there a better way to set this up?

May
27
4 months ago
Activity icon

Replied to Product Designer Looking To Partner With A Laravel Developer :)

Sorry, just seeing this. That would be awesome! Can you send me an email? nathan at bldg13 dot com

May
20
4 months ago
Activity icon

Replied to Product Designer Looking To Partner With A Laravel Developer :)

@bugsysha Any chance you are looking for a side project?

May
19
4 months ago
Activity icon

Started a new Conversation Product Designer Looking To Partner With A Laravel Developer :)

Hi—it's been a few yeas since I've been on these forums! I hope it's ok to post this here in General. Happy to move it if necessary.

A few years ago, I spent some time here leaning to program and build a web app. I was able to get pretty far with the help of Jeffery's tutorials and these forums. I launched a super early MVP of an idea I called MatchUP over at https://matchup.us. The idea is to help athletes find pickup sports and tournaments, and teams find subs, etc.

Then I left the web design/development world for a role designing native iOS and Android apps.

Since then, the site has gone pretty much untouched for the last 3 years. I still think the concept is solid and worth pursuing.

I'm certainly not the first to pursue this concept but I don't think anyone has really succeeded. I have a lot of thoughts and ideas though how to potentially make it work.

I am currently freelancing now and have some time again. I'd like to get back to working on Matchup and make some improvements as well as add some important features.

I believe my best hope for getting this project off the ground would be for me to focus on the design and to find a partner to help build it.

You can get know a bit more about me here: http://nathangross.me

Please understand, I don't have the funds to hire someone to work on it. I think there is a possibility to make a business out of it though—but that would be a bit down the road.

Please reach out if you'd be interested or if you have thoughts or ideas on how I might get this thing off the ground.

Thanks for your time!