jcc5018

jcc5018

Member Since 5 Months Ago

Experience Points
5,360
Total
Experience

4,640 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
49
Lessons
Completed
Best Reply Awards
0
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 2
5,360 XP
Sep
24
1 month ago
Activity icon

Started a new Conversation Counting Models Associated With Category Along With Children.

Hey again, So I am still trying to figure out how to do this. I have managed to get the parents and child models for display when clicking on a parent category, but I am having trouble figuring out how to get the count of these models without having to run the whole loop again in a different method just to count things.

I have the parent count simple enough, but i need to also count the associated children models associated with each category.

Basically I need (Count of hobbies associated with parent + Count of hobbies where tag_id = $category->id through a M:M polymorphic relationship

in my Categories controller:

public function getCategories()
    {
      $hobbycount=Hobby::where('status',1)->count();



$categories=Tag::whereTag_type('80')->get();
$categoriesCT = Tag::whereTag_type('80')    ->get();  
    
// $categoriesCT = Tag::withCount(['hobbies' ])
//     ->get();
    //    $categories=Tag::whereNull('tag_id')
    //            ->orderBy('tag')
    //            ->get();

// $hobbies = Tag::withCount('GetChildrenCategories')->get();


               return view('frontend/hobbies/browse',['categories'=>$categories, 'hobbycount'=>$hobbycount, 'categoriesCT'=>$categoriesCT]);



    }

The view: Getting undefined offset errors

 @foreach($categories->whereNull('tag_id') as $category)

            <a href="/hobby/category/{{$category->tag}}">
                <div class="card card-grid border-dark mb-3">
                    <img src="..." class="card-img-top" alt="...">
                    <div class="card-body">
                        <h5 class="card-title">{{$category->tag}}</h5>
                        <p class="card-text">{{$category->description}}</p>
                        <p class="card-text"><small class="text-muted">{{$category->hobbies->count() }} +
                        @forelse ($categoriesCT->where('tag_id',$category->id)as $CCT)
                        
                        {{$CCT->hobbies->count() }}
                        @empty  
                        @endforelse

                        Hobbies</small>
                        </p>

Tag Model -- categories are tag type 80

public function hobbies()
   {
       return $this->morphedByMany('App\Hobby', 'tagable');
   }

   public function tagable()
   {
       return $this->morphTo();
   }
   public function tag_type()
   {
       return $this->belongsTo('App\EnumOption','tag_type'); // Tag Type id= 16

   }

public function GetChildrenCategories()
   {
       return $this->belongsTo('App\Tag','tag_id')->where('tag_type', 80);
   }

    public function GetParentCategories()
   {
       return $this->hasMany('App\Tag','tag_id')->where('tag_type', 80);
   }
// recursive, loads all descendants
public function childrenRecursive()
{
  return $this->GetParentCategories()->with('childrenRecursive');
}

Hobby model incase i need to go about this the other way:

 public function tags()
    {
        return $this->morphToMany('App\Tag', 'tagable');
    }
     public function categories()
    {
        return $this->morphToMany('App\Tag', 'tagable')->where('tag_type', 80);
    }

Tags Table: id, tag,tag_id (parent), tag_type (80), description Tagables Table: tag_id, tagable_type, tagable_id

Sep
06
1 month ago
Activity icon

Replied to Project Setup For Supporting Model Types That Dont Have A View In Itself?

well, in this particular case, the languages, states and countries, i already have the data for. so as of now, there would likely be little use for updating or anything, unless countries start changing their names or get new state divisions, which is possible, though rare. I actually seeded my tables with a json file so most of the data is there already, but i just need to know where to put the query to pull it.

I guess my confusion comes in that I know the basics of what model views and controllers are supposed to do. I assumed that every model should have its own controller which in return populates a view, but it doesnt really work well that way if you need to pull data from several tables.

Languages for example, would need a CRUD for if i want to add supported languages, but the file im working with now is simply a basic Select statement in order to populate a dropdown list that would then be associated with a user.

So, making a language controller probably wouldnt handle that association, So i'm assuming that I need to call several models in a settings controller to get the required data sets for a particular view. Right?

So if i creating a "usersSettings" controller, the index would pull from the locations, country, and state models in order to pass the required arrays to the view?

Or is this another case where i need to create a helper, or one of those other class types. I start to get confused when I need to utilize those features. (facades, service providers, helpers, putting things in the boot class etc) I dont really get what they are for and when i need to consider them over a basic controller.

Activity icon

Replied to Project Setup For Supporting Model Types That Dont Have A View In Itself?

Hey, thanks for your reply, ill take a look and see if it will do what i need.

Sep
05
1 month ago
Activity icon

Started a new Conversation Project Setup For Supporting Model Types That Dont Have A View In Itself?

I am working on my settings page of my project and came across another question about best practices.

In my application, I have several tables for things such as languages, states, countries, ect that would be used for settings or addresses, and other related functionality.

So i have a model set up, and im assuming that I should create a controller for languages and other similar tables to pull the records from Db, and other typical CRUD applications.

But typically the controllers go to specific views. But my use of these data tables (language, countries, states, etc), don't populate a view in itself, (except for maybe a create/update view) but instead just a drop down list that a user can select from in various forms.

So do these types of things need to go in their own controllers? Or some other helper or other class type?

Can (should) you pull data with one controller and pass it to another before finally reaching the view?

Would i need to create a partial view just to display simple drop down menus? or do i call it within a USERSETTINGS controller or where ever needed?

The call itself is simply a $languages= select * from languages where status = active then a foreach loop to populate a drop down. But I'm just not sure where this DB call needs to go in order to access it in my blade files.

Also, can laravel handle conditional form selections on its own, or do I need to find some JS to do this? In other words, a user selects an option from one drop down, and then drop down 2 updates its options based on selection of first.

Aug
29
1 month ago
Activity icon

Replied to Parent Child With Related Model

I Almost have it figured out. Now I was able to get the Hobbies associated with the child categories displayed, but i need to include the hobbies with the parent category also. (P, C,C,C) How do I add the parent to the array of keys as well? Can this code be simplified?

//Hobby Controller

public function index($category)
    {
 $categories= Tag::whereHas('GetChildrenCategories',function($query) use ($category) {$query->whereTag($category);})->pluck('id');


 $hobbies = Hobby::whereHas('categories',function($query) use ($categories) {$query->whereIn('id',$categories);})
    
 ->get();

        return view('frontend/hobbies/index',['hobbies'=>$hobbies, 'categories'=>$categories]);
    }


//Tag Model

class Tag extends Model
{
    public function hobbies()
    {
        return $this->morphedByMany('App\Hobby', 'tagable');
    }


    public function tagable()
    {
        return $this->morphTo();
    }
    public function tag_type()
    {
        return $this->belongsTo('App\EnumOption','tag_type'); // Tag Type id= 16

    }

public function GetChildrenCategories()
    {
        return $this->belongsTo('App\Tag','tag_id')->where('tag_type', 80);
    }

     public function GetParentCategories()
    {
        return $this->hasMany('App\Tag','tag_id')->where('tag_type', 80);
    }
// recursive, loads all descendants
public function childrenRecursive()
{
   return $this->GetParentCategories()->with('childrenRecursive');
}

Also, when Displaying the results, I have a call to display the name of the tag under each hobby, but when it displays, i get it displayed as ["TAG"] opposed to just Tag. How do I fix this?

        <p class="card-text"><small class="float-left text-muted">{{$hobby->categories->pluck('tag')}}</small>

and Finally, on the browse page that selects the parent level category, i need the total count of all hobbies associated with the parent or child tags. How can I do this without having to run another query again?

Aug
28
2 months ago
Activity icon

Replied to Parent Child With Related Model

Also, I need to display the subcategory on each hobby card, so when i add this code.

<p class="card-text"><small class="float-left text-muted">{{$hobby->categories}}Sub-Category</small>

within a foreach loop of the $hobbies as $hobby I get the proper subcategory listed under each hobby (though not filtered by main category) but it gives the full data array.

"id" :68, "tag":"Dance","tag_id":66,"tag_type":80,....

so if i make the call {{$hobby->categories->tag}} though, I get an error

"Property [tag] does not exist on this collection instance. "

So I really dont know what I'm doing wrong in all this.

Activity icon

Started a new Conversation Parent Child With Related Model

Hey guys, I have been trying to figure this out a few days now, and have found many resources creating parent child relationships, but I am still having a lot of difficulty getting the associated model of the Tags (categories) that I am trying to display. I am getting close, but still missing something cause I still don't have a full understanding of the eloquent way. I have read the documentation, and watched/ read many videos/ articles with no luck.

So here is what I need to do.

On browse page, i have the parent category tags successfully listed., But i will need a count of the hobbies under the parent tag and all children.

But the bigger issue, when i click on that parent category, it needs to go to an index page of all hobbies that are under that parent category along with the children in a flattened display. I successfully listed the hobbies that are not under a sub category, but I can't get the rest and its driving me nuts.

I have a polymorphic M:M relationship between hobbies and tags, All that is set up correctly. I also have a few different relationships set up based on recommendations from other articles i have read, but im not sure if all are needed, or which i have to use. I've been trying different things in my controller, but most of what i try either produces an error, displays only the hobbies of top level categories, or displays all the hobbies. I do have the child categories successfully displaying if I do a for each loop on them, but I don't know how to pass the id's of those categories to the hobby query to get the hobbies associated with that array.

Here is my code, again, let me know if there are functions I don't need for this result. Right now I think this code is performing multiple queries, so if i can redo this to only be one query, that would be ideal.

//Hobby Controller


    public function index($category)
    {

//get subcategories
$categories= Tag::whereHas('ParentCategories',function($query) use ($category) {$query->whereTag($category);})->get();

//needs to pull all hobbies tagged with category and subcategories of passed variable. 
 $hobbies = Hobby::with('categories')
     ->where('status', 1)
 ->get();


        //$hobbies=Hobby::find($category);
     //$hobbies=Hobby::where('status', 1)->get();


        return view('frontend/hobbies/index',['hobbies'=>$hobbies, 'categories'=>$categories]);
    }

//Tag Model (categories are in the tag table with tag type of 80 (category))


//This function works to get child categories
public function ParentCategories()
    {
        return $this->belongsTo('App\Tag','tag_id')->where('tag_type', 80);
    }

     public function ChildrenCategories()
    {
        return $this->hasMany('App\Tag','tag_id')->where('tag_type', 80);
    }
// recursive, loads all descendants
public function childrenRecursive()
{
   return $this->GetChildrenCategories()->with('childrenRecursive');
}

//Hobby Model

 public function tags()
    {
        return $this->morphToMany('App\Tag', 'tagable');
    }
     public function categories()
    {
        return $this->morphToMany('App\Tag', 'tagable')->where('tag_type', 80);
    }
Jun
08
4 months ago
Activity icon

Replied to Creating A Relationship With A Look Up Table

I'm starting to think i better just hire someone who knows what they are doing... this is just too big a project for just me. I've got enough knowledge to mostly follow along, but actually building something is totally different story.

Anyway, I do thank you for answering.

I did know that $genders was the array of values just wasnt sure the best way to perform the join to pull up genders within eloquent. as the options table would only be displaying question_id =1 if the Genders id was 1 obviously.

But ill figure it out eventually. one step at a time.

In case your are curious, this is just a sample of what im working with....

Wireframe Docs

Database

Activity icon

Replied to Creating A Relationship With A Look Up Table

First, thank you for your reply.

I've got a few questions.. you, and several other examples i've seen online create your relationship as "belongsTo(Options::class)

but in the Laravel 7 docs at least, is says to use return $this->belongsTo('App\User');

Is the App\ ___ just another way of saying __::class or is this new to Laravel 7?

As far as scoping, in your example would that $genders be in the options model? or somewhere else?

In my set up, like i said, i would have two tables, 1, is just the "labels/ questions" (ie, Genders, status, relationship status, etc) 2 provides the options for those labels so i would need to create the join, but im not positive how to do that with eloquent. But maybe i dont need to worry bout that at this point.

thanks

Jun
07
4 months ago
Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

Sir, just don't start future replies with "do you really think...." Cause to me that along with your italicized "really's" sounds a lot like "you are a fool if you think you can do this". Maybe you meant differently, but your delivery sure sounded like a put down to me. And I've gotten tired of people telling me I can't do things, so I'm just at a point of saying "watch me"

But I'm going leave this at that. I've said what I needed to say. If you still disagree, we will move on. Take care.

Activity icon

Replied to Creating A Relationship With A Look Up Table

@snapey although I here what you are saying as far as queries and may end up doing just that for some options. the idea behind this thougg was to mimic enum data types which essentially do exactly this. They store a number opposed to a string to which again reduces DB size.

And it helps keep data integrity as well by having predefined values. I know I could code some of these things in, but some options may need to change over time and I don't want a whole bunch of small tables with 3-10 rows each, when one table should be able to accomplish the goal.

So assuming I stick with this lookup table which from my research is a fairly common practice, do you know if I can or should define the where clause with the relationship definition or wait till the retrieval statements?

Im asking because I really think I read something about adding ->whereSomething type methods to the end of a line, but I can't find it again and don't know if it was after the relationship definition (hasMany,belongsTo...) Or after the Find query.

I guess I'll just keep going and see what errors I get when I get to it.

Thanks anyway

Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

@martinbean your response was condenscending from the start. And continues to be with your recent reply. It was in no way related to how snapey replied.

I may not have the experience as you, but I don't appreciate asking questions and having people like you shut down my goals with sarcastic replies as with your italicized words when you don't have any information about what I'm building at all. You don't know how much time and effort I've been putting into this project trying to ensure it won't be a flop. I'm limited on resources so I'm trying to do as much as I can myself before trying to hire someone.

You may be right in that it doesn't matter, but the way you addressed it is not right. I don't know what you do, but I'd advise you stop putting down people's goals no matter how silly they seem to you because for all you know, I may very well be the next mark z, or maybe not, time will tell. A little reminder about all the people who told inventors we would never fly or reach the moon should be enough of an example for you. A simple "they probably wouldn't matter much at this stage" would have likely been enough for me to move on.

To everyone else, thank you for your replies. I think I have the answers I need.

Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

@snapey I guess you have a point. I do think i question these little things cause for one, I'm still new and want to make sure things will work smoothly. But two, I can't afford to fail, so maybe I do spend too much time thinking about things. Though in all honesty I think I knew the answer for this question, I just wanted some verification. The relationship question on my other post im still not sure about. Haven't checked for replies yet. But thanks regardless

Jun
06
4 months ago
Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

@snapey I'm trying to build it, I'm fairly new to the programming side, but i have a well laid out 400 page plan and an interactive prototype of the program built. (if i could only connect that prototype to a Data source, i'd be up and running.) I have a fairly good idea what I need to do, just not a full idea exactly how to build it. (in other words i'm the architect, not the builder.) But i'm doing my best to build as well because I don't have the money to hire someone.

I ask these kinds of questions because it cost money to run queries, particularly if i use a cloud service. For a small app, may not be a big deal, but if i come anywhere close to the numbers i mentioned, it will be. So as I said before, I'm trying to plan for that instead of having to spend even more time and money later trying to fix things. I understand there are things like cache that would reduce the number of DB request, but I don't yet have a full understanding of that either, so I just want to design my program to be as cost efficient as possible.

Activity icon

Replied to Creating A Relationship With A Look Up Table

i dont know, i wasnt sure if it was required to define both sides of the relationship or not. if for example a group is of type "business" that may have option 1 in the group table under group_type and so forth. To me, i would know to go to the options table to see what option 1 is, but i just wasnt sure what laravel's requirements were when making the models. I would much rather not have to define all the relationships, but I'm trying to figure out if i need to in order for the eloquent queries to work properly,

Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

i really don't like when people question me like this "Do you really think you’re going to get 100 million users to your application? If so, I can assure you that you’ll face many other scaling problems before storing “big” integers versus “small” integers becomes a problem." - @martinbean Those are the numbers i found with my research of other social media sites. Facebook obviously has a lot more being a global site with about 5 billion active users. I don't know if i will reach those numbers or not, but that sure is a goal. But as usual, people miss the actual questions of the post and focus on what they think is unrealistic.

It doesn't matter if i get 10,000 users or 100 million or 1 billion. THE QUESTIONS are not about scaling, They arent about if i will reach that number of users.

The questions were :

Am i right in my statement that each reference would end up producing an 8 byte column regardless of actual digits used? or are sizes variable based on actual value?

And

So is this something i should go through and try to refine for DB cost, or due to caching, is it not really worth the hassle of fixing?

I'm fully aware there are other issues that i will have to face, but I also would rather get things right the first time rather then spending more money later having to fix things if i do grow to a much larger site. This is just 1 of many things I will have to figure out and is the current thing i am facing as I try to build my site.

Stop putting plans/ people down just because you think small. You don't have a clue what my application is.

Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

im building a social network, and for this particular example, i have a pivot table where users like particular topics, but then there are 6 different ratings that further expand their experience or interest in the topic. (such as are they a beginner, intermediate or expert in the topic) The average social media site (twitter, pinterest, linkedin) tend to be around the 100 million active user mark from my research. If i have similar user base, and those 100 million people each have a connection with 1:M topics, (I have close to 800 potential topics of interest so far) then yes, i believe a couple hundred million rows is accurate if not an understatement.

I dont have 100 million options, i have 100 million x 6 foreign keys referencing those options. The options themselves for that particular table and 6 questions may be about 20.

Activity icon

Replied to Creating A Relationship With A Look Up Table

no, its two different questions related to look up tables... typically on other sites if i post several questions in one post, I'm told to make them separate, so thats what i did

Activity icon

Replied to Lookup Table Int Size Defeats Purpose Of Table

well probably isnt a big deal for the smaller tables, but my reference tables, i think it would be a big deal. The options table itself may not have that many total entries as of now, (for 65 questions, i have 278 potential options) and that will grow. But when i have a table that has 6+ references to this lookup table that is 6x8 bytes, multiplied by a couple hundred million rows

So in this case, yes, i think i would want to reduce the Data size from 8 to 2 or 1 byte.

Activity icon

Started a new Conversation Creating A Relationship With A Look Up Table

I have several tables that reference 1 lookup table to provide a list of possible options that can be entered in that column. As of now, i have 65 different 'questions' each with their respective options for the columns in question. As you can imagine, this creates a lot of relationships to the Questions/ Options tables.

So I get you would have a public function status() { return $this->belongsTo('App\Option','status'); }

for each of the different models, that reference the lookup table. But I have a few questions

  1. Since the requesting model will be providing an id of the options table, and the options table links to the questions table with its own FK, can I or should i define the specific questions to limit the allowable selection?

for example, belongsTo('App\Option','status'); ->where question = Group status (i'm not sure the proper syntax, or how to handle the join between the question and option table, as the options table only displays the question_id)

In my DB this would mean that only id's 89,90,91 are available choices for that particular column

  1. Do you have to define the hasMany relationships to every referencing table? Because that will create a very long list of relationships. If you do need to put the hasMany, is there a way to make it more variable so im not needing to create the 65+ individual entries?

Again the only purpose of these tables is to provide the data that may either be in a radio or dropdown selection for various forms or settings. Some items will likely never change available values, but some may be added to as the site grows.

Thanks

Activity icon

Started a new Conversation Lookup Table Int Size Defeats Purpose Of Table

So ive been designing an app and i wanted to use a combination of lookup tables to populate certain items such as statuses, and other options that a user may be able to select from. I have 2 tables for this. 1 is the "question table" [ID, Name] and the 2nd is the "options table" [ID,Question_Id, option] which has the various things to choose from as you would expect. This is to mimic the ENUM functionality without the pitfalls of ENUM data types. no additional data is included other than timestamps for both.

So the idea behind this was to 1, keep data consistent, and 2, reduce DB size as referencing a integer was supposed to be smaller than using varchars in the DB column. But Laravel's default of using bigINT for everything would automatically make every entry 8 bytes if i understand it right. Which kind of defeats the purpose in most cases. Where a simple ID of 0-255 should only be 1 Byte.

Am i right in my statement that each reference would end up producing an 8 bye column regardless of actual digits used? or are sizes variable based on actual value?

I'm thinking a smallInt would be more than enough for this particular Table. There are some other tables as well that have fairly small datasets where even a TinyINT would be more than enough instead of using big ints.

So is this something i should go through and try to refine for DB cost, or due to caching, is it not really worth the hassle of fixing?

Also, within Laravel 6/7 they have that new function foreignID that replaces the

$table->unsignedBigInteger('type'); and $table->foreign('type')->references('id')->on('table'); lines.

but is there a way to change the INT size for the foreignID fields for different tables, or would i just have to stick with the old method if i want to define INT size?

And if you were to add a length to INT, such as BigINT(3) does that still produce a 8 byte column or would it be reduced?

Thanks

May
23
5 months ago
Activity icon

Started a new Conversation Laravel 7 ForeignID() Migrations

Hey, I have been working on getting my 170+ tables that I generated from my database set up correctly, but I am having difficulties with this foreignID functionality. I went through all my tables and replaced the FK's to $table->foreignId(foreign_id')->constrained(); as shown in the Laravel 7 documentation. My understanding is that this would replace the need for two lines of code like this. (Most all the previous inquiries I've found on the topic utilize this way and not the new way Laravel offers. )

$table->unsignedBigInteger('user_id');
 $table->foreign('user_id')->references('id')->on('users');

But when I go run the migration:fresh option, i get errors on the first table with a Foreign key that says:

General error: 1824 Failed to open the referenced table 'users' (SQL: alter table ad_campaigns add constraint ad_campaigns_user_id_foreign foreign key (user_id) references users (id))

I'm going to assume this is because the users table hasnt been created yet. But I really thought the whole point of this foreignId() function was to make things easier. I've read in other places that perhaps foreign ids have to be created after everything else, but that implies that i would still need to add

$table->unsignedBigInteger('user_id'); in addition to the foreignId() or am I expected to create an entirely new set of migrations that adds all the respective foreign keys? Like I said, I have 170 tables, I really would prefer not to have to go through and edit everything again, or add another set of migrations just for something that i thought should be handled on initial creation.

I also need to know if on the pivot tables, after defining the relevant foreign keys, should you also be declaring them as combination primary keys? Thanks

$table->foreignId('equipment_id')->constrained();
           $table->foreignId('vendor_id')->constrained();
		$table->primary(['equipment_id','vendor_id']);