Build your own packages in Laravel | Arturo Rojas | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Build your own packages in Laravel

teacher avatar Arturo Rojas

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

8 Lessons (57m)
    • 1. 1 intro

    • 2. 2 overview

    • 3. 3 new project

    • 4. 4 composer

    • 5. 5 migrations

    • 6. 6 trait

    • 7. 7 test

    • 8. 8 share

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Learn how to turn your ideas into packages and share them with the world

In this course, I'll take you through the process of creating a small, yet useful package. I'll show you how you can test and share this package so you can integrate it with any other Laravel project.

With the principles learned in this course, you will be able to turn your own ideas into packages that you can share with everyone.

Meet Your Teacher

Teacher Profile Image

Arturo Rojas


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. 1 intro: hello and welcome to this new course on lateral development. We are going to learn about packages. Lateral itself is built around this concept, and if you have developed a lateral project in the past, you are either knowingly or not using packages in your projects. But even though lot of is built around the concept of packages, there is very little information in the documentation that explains how you actually develop them. There is no explanation about the composer to Jason File, which is a key component in creating your packages, and there is no information about best practices that you should follow when you are creating a project of this type. So in the scores while we're going to create is an activity look package that you can use in any other project, and it will log activity that happens on your models. For example, if someone creates a record using a model that is being monitored, you will be able to see who changed the record. When did it happen and what was actually changed in the process. By the end, you are going to have a simple package that you can use in any other project, by simply requiring it in the composer that Jason File. We're going to learn how to create configuration files and migrations for your package, and also we are going to allow level toe automatically discover your package so that the installation of your package is very simple. Hopefully, by the end of this course, you will gain knowledge about how to create your own packages and using those packages in any other project. 2. 2 overview: before we start coding. First, let's go over the project overview so that we have a clear understanding off what we want for more package. First of all, let's discuss what is the goal of this package? What do we want to do with it? Or more precisely, what we want other people to do with our package. The goal here is to create a package that can be easily integrated into any other project so that we can monitor the activity off the application. We want to keep track of data changes in the database. If someone changes, creates or the leads a record. We want to know who did it when what data was changed and how the data was changed. So they see his way to accomplish this is to just drop a trade class into our models that will immediately start. Keep tracking off the events that happened on that model class. We can make use of the models observable events, more specifically, the created, updated and deleted events. But since this is a package that can be used in any kind of project lateral project, specifically, there might be cases in which the project doesn't even have authentication, so we don't have a way to identify a user for except Or maybe the project uses a table structure for the users in which the user is not identified by an email, but rather a unique user name. In this case, we're going toe over a simple configuration file in which the user will be able to provide the column name by which the user is identified in the database. And also, since we want to keep our activity look in the database, we are going to provide a migration file So the latter Vulcan take care off, creating this table by simply run and PHP artisan migrate. Lastly, we're going to take our package and store it in packages, thought or so that our package can be easily discovered by other users. Now that we have a clear goal in mind, let's start setting up our new project, and we're going to do that in the next video 3. 3 new project: There really is not a lot of information out there on how to structure your packages. For example, you can have them in their own standalone folder, or you can choose to have them inside a lot of a project. Whatever path you choose, it really doesn't make much difference. The end result will be the same for these scores. However, I will follow the lateral project approach, so I will start by creating a brand new lateral project which will serve as a container for all of my packages. I'm going to work with the assumption that you already have homesteading stalls. If that is not the case, you composite video and go to the laudable website and inside the documentation, look for the getting started homestead section here. All you have to do is follow the installation and set up instructions which are fairly I would recommend to use very 12 box in vagrant for the virtual machine. Once you have followed the installation steps, you can come back to the terminal and start your veritable machine using vagrant. No note that you have to be inside the homes that folder to do this. Don't get nervous if you see this warning here? Remote connection disconnect. Retrying is gonna take a couple of tries, and this just means that it is trying to connect to the veritable machine. But the little machine is still booting, so give it a few seconds and you will see the message machine booted and ready. There you go. Once the machine has started, you can log into it by using vagrant. Ssh! If you follow the configuration steps correctly from the documentation, you should have a folder called Code. So I'm going to see the into it. And this will be the point by which you can share files between the veritable machine in your operating system. Here, I'm going to create a new lateral project. You can do this by simply typing a lot of ill new and the name of your project. In this case, I'm just going to call it not a. This process is gonna take a few minutes, so I'm going to make a pause here and come back when it's done. Now that our application is ready, let's CD into our project folder. In this case, it's notable in this Project folder. I'm going to add a new folder called Packages. Here is Where I'm Going to keep all of my package products Inside the Packages folder. I'm going to create another folder, which will be the name off the vendor. In this case, I'm going to use my get hub user name. Let's go inside that folder and let's create another folder, which will be the package name. Let's call it activity. And finally we are going to create another folder called SRC, which is short for source. Here is where we will keep everything that is used under the package name space models, Trades said of his providers, etcetera. And with this, we have a folder structure for our package. In the next video, we're going to initialize our package with its own composer Fire. 4. 4 composer: Now that we have our project folder structure created, we're going to initialize or package with its own composer that chase and fire. Every package needs a composer, the Jason File union with a fine all of the aspects of our package like its name, license, third body requirements and much more. For now, we will just create a basic file and later on, we will add more to it. Since we are working with in Homestead Composer come spring stuff. So all we have to do is within our package folder. In this case, it's called Activity. We just have to type compose it in it. Now we just have to follow the instructions on the screen to create are very basic composer that Jason fire. We start with the vendor in package name. As we said before in this case, I'm going to use my get hub, use her name, but you can use yours. So just type in the vendor name, forward slash and the package name entered. You can feel in the description here, but in my case, I'm just gonna leave it empty. Same thing for the author. We're just gonna person just get for the minimum stability, I'm going to use their so that we use the main development branch as the minimum stability . If you want to use tag releases and get home, you can define which one is the minimum stability. For example, may be version 1.0 point zero. In this case, I'm just going to leave it us there for the package type. I'm just going to use project for the license. I'm just going to leave it empty for the default Valley and stains are package is not going to require any dependencies. I'm going to say no. Here and here is where Now we can see an overview of how our composer that Jason Fire is going to look. So you have to do is confirmed by saying yes. And with that, we have our own composer that Jason file With this fire created, we can actually include are empty package into the container product. We do this now so that we can test the package later on. Don't worry about making changes to the composer file. What we have to do is run composer update, and that will take care of everything for you. Now I'm going to open my project in the editor I'm going to use this was studio cold, but you can use any editor you prefer. As you can see here, I have the project open in visual studio code. We have our container application called Bladder Bill, with its default full of their structure. Plus, we have the Packages folder with the vendor name and package name and within it the service folder. And let's not forget about the composer the Chase and found that we just created before loading up these empty package into our container application. We are going to make a couple of modifications to the composer that Jason founded we created a few minutes ago. First, we're going to tell the parent application which files should be out of load. We can do that by adding a new section cold out too low. And inside that one, we are going to add another section called PSR for here with a fine the name space that the package is going to use. In this case, it's going to be the vendor name and the package name like so we're going to use to backslash is here in the end if package name followed by another two backslash. And we're going to say that this name space should out load all of its files from the service folder. This should be wrapped around Quelch like this. This source folder is relative to the location off the composer The Jason File. The next section has to do with a feature that was added to Lauraville 5.5, in which the parent project can how to discover the service provider class inside the package. Now, keep in mind that even though it is a common belief that all packages should have a service provider, this is actually not entirely true. Your package should include a service provider class if you need to out a load any resource in advance, like configuration files, CSX classes or table migrations. If your package does not need to do any of that, then you can skip the service provider CASS. In our case, we're going to need to publish a configuration file as well as a migration file for our table in the data piece. So we're going to need another section called Extra Inside of That. We are a section called Level and then another section cold of either's. This section is going to be an array, so note the square brackets here. We're going to provide the names off the service provider classes that we wish to include or be out of discover by the parent project in this case is just going to be one, which is located in the name space of the project, which is the vendor name, package name and then the name off the service provider class. Let's call it Tiv Ity service providers. Now this class doesn't exist yet, so let's create it. First, let's say the file and then go back to the tournament within the Project folder. You can simply type artisan make provided and then the name of the class activity service providers. Now back in the editor, The new provider class was created inside the providers for, so let's move it into our package source folder right here. Let's not forget that after moving the found, we still have to change its name space. So let's change it to the vendor name Capital team, this case and then to package name. We were getting to more details about the contents of this class in a later beat. So for now, we're just gonna save it in closing. Now we have our packages. Composer, though Jason filed ready to be used. So go ahead and open the composer. The Jason file about the container application, which is down here inside the require section. Let's add one more line for our package event were named and package name. And for version, we use death Nash Master. The last thing we have to do before important this package into these continue application is to lead level no. Where the files off this package recites We're not going to use any known repository and I get up for packages. We want the continued application to link the files directly from the fire season. To do that, we're going to add a new section right before require called reports stories. And it's actually in a race who we have to use square brackets. And for the first item, we open pretty records. And here we at type these were telling that this repository is located in a path in the fanciest. Then we have to provide you a rail to the files, and this is relative to the location off this composer Jason. So in this case, we have to look for the files inside packages the vendor name in the package name. Lastly, we are another section called Options, where we tell composer to use his sibling. That means that files will not be copy it from the package location into the vendor folder of this project. They will simply be referenced with a seemly. Now we can save this file angle to the time in tight composer of If everything went according to plan, you should see this line here saying in selling vendor name, package name seemed linking from packages than their name and packaging. That means that the package was successfully imported and installed. You know, a parent broad. In the next video, we're going to create a migration file so that we can create the table for our activity log in the data base and also create a very simple configuration file so that we can deal with different types of authentication and user identification 5. 5 migrations: in this video, we're going to focus on the database section off our package, which means that we have to provide a migration file which will be executed automatically whenever we type in Artisan my crit. And we're going to tell that about where he has to look for the migration files within the package. So first things first, we're going to go to Terra meaner and within our parent project folder, we're going to type PHP artisan. Or we can just type artisan for short make migration and let's call it create in the table . Name will be activity locks so the migration name will be create activity, locks table. We provide the dash dash, create with the table name so that letter will can scaffold some of the code for us. So in this case, the table name is activity locks. Now let's go back to the editor and we could look for the new migration file inside the parent project within the database migrations folder. Here we have to migration files that come with a lot of ill by the fault, and they are used for authentication, and also we have the new one right here. But we need this file within our package. So in our package folder name, which this one we are going to mimic laterals folder structure for that of his migrations. So inside the package folder, name its creator in your folder in this college database and inside that folder create a new folder called Migrations and we are going to move our migration file inside this folder . There is no name space to worry about. Now we can start editing the migration file in at all the columns that we need. Let's add a column to identify the user who made a change. This will be a string column called User. We also need another column to store the I P address of the user who performed the change again. This is a Stream column called I P Address. Now we need to know what kind of action was staking on the record, whether it was created or dated or the leader. So let's create a column for that. This will be another string column called Action. Let's have another column to store the model name that was changed. This will be a Stream column called Model Name, along with the model name. We will also want to know what was the I D. Off the record that was changed in case of updates or the elites. So let's create another column. This time it will be an unsigned integer called Model Heidi again. In the case of updates and elites, these will carry the idea of the record that with modified or deleted in the case of new records, it will be the next consecutive I D number from the table. This way we can always keep track of what record was changed. But we also want to know how the record changed in the case off creating updates. So let's have a new string column and call it payload. Since we're not gonna have any values in case of the elites, this column can be no, don't forget to save the file, and I think that would be enough. Now we want to tell arable how to load this migration file from the package, and this is done via the service provider class. So let's open our service provider class, which is here inside the package name, folder, and inside the boot method, we can say this load migrations from, and here we provide a path from which the migrations can be loaded. So let's just type the year, which refers to the current folder. And since the service provider is actually within the source folder, we have to go up one level. So let's upend forward slash start dot forward slash and this will take us out of the service folder. And from here we can just refer to the database holder and also the migrations for their inside it so that a vase migrations. And with that simple line, lateral now knows that whenever we run PHP artists and migrate, he not also has to look for migrations inside the common migrations location within the database Migrations folder in the parent project, but also has to look for migration files within the package in this path. And we can actually test this migration process in our parent project. Homestead already comes with a pre defined that of a schema called Homestead. In fact, if we go to the Terra meaner and we try to connect to my SQL using the homestead user with minus you homestead and we also have to provide minus P so that we provide a password, and the password is just the word secret. I believe if we type show schema No, that's not it. I think it's show that a base or maybe data basis. There you go. With these, we can see all of the database scheme is that we have available and within those we have thes homestead schema. We can use that for a simple test. I'm going to use a program called Sequel Pro so that I can have a nice you I to navigate the batteries. I am already connected to the home state schema in. As you can see, there are no tables created. Now let's go back to the editor so that we can set up the database connection in our product inside our parent project. Let's open the dot E. M v file and here all we have to do is change the user name to Letterman. If it's not like that already, and for the password, we just use secret and that's it. Saved the file. And now let's go back to the lead a minute. Let's exit out off my SQL. I'm gonna clean out my screen real quick in here inside my parent project folder, while I have to do is type Artisan. My great. No, actually, that was my mistake. Let's go back to the editor real quick. And it's not lateral for the database and user name. It's actually Homestead. Sorry about that. So that a base homestead used her name Homestead in Password Secret. Okay, let's try that one more time back, Dominion, Artisan, Migrate. And, of course, you have to save the file as well. Sorry about that. Back to the editor. Save the file back to terminal. Let me clean this up a little bit in one last time. Artists and migrate. OK, that's much better. As you can see, letter will not only created the password and user tables, but he also created the activity locks table that we provided in our package. In the next video, we're going to create a trade class that will be in charge off monitoring the activity in the model classes. 6. 6 trait: in this video, we're going to create a trade class. There is going to be easily drop into any model class and immediately start monitoring activity. Let's start by creating a new file. We'll create this inside the source folder. Okay, let's call it activity, not PHP. That's type in the regular PHP code. Here. First of all, the name space will be the vendor name in the package name. Then we simply creating trade class with trait called activity. And we don't need to close yourself here, so I'm going to remove it. So the main idea here is that this trait is going to be dropped into a model class in the way we monitor activity in that model class. It's by time into the model events. A good way to do this is by using the boot method which is called lick static. Good. And I forgot the function public static function, boot and inside the boot function, we create three methods which are aesthetic created. This receipts a closure that passes seen the model class and inside here we can take actions whenever a record is created in our model, the same way we can take actions whenever a record is updated with the static updated miss it and finally, the static deleted method. Now, the problem with this approach will be if the model in which we are dropping in this trait already has a boot function, which will override the spook method in the trade and none of these who will take effect. Fortunately, we have a way for the trade to merge with the booting process of the model by simply changing the name of this method to boot and the name of the trait. That way, if the model has a food method already to find, it will merge with it in this event will be executed accordingly. Now, what we want to do inside these three methods is to leave a record of the activity. So what I'm going to do is call another method cold static. Look, this function doesn't exist yet, but we're going to create it in just a second. I'm just going to add that function call inside all three events and now up here before the public static function boot activity. Let's add another static function called Lord. We still don't know what we want to pass into this method, but we're going to figure it out in just one second. So let's think for a second what we want to do here. First of all, we want to leave a record off what just happened, and we want to answer three simple questions. Who did the change? What was changed and how it was changed. First off, let's answer these two latter questions. What and how we already know that the model is passed on to us in the event this model class is a snapshot off the model at the time the event happened. So what we can do is fastest model into the log method, and we do that in all three instances. Then we modify the signature of their call up here, and with that, I can identify what was changed. So I'm going to store that in a viable called model name first. And here I can get the moral class name by using class base name, and we pass in the mortal instance. So this will give me the class of the model or specifically the class name. Additionally, Aiken Store, the I D of the record of was changed in that store that in model I D. And we can obtain that by simply calling model get key. So we have what was changed. Now we want to know how it was changed. And we can do this by just examining what was changed in the model the store that into a variable cold payloads. Since these is going to be stored as a string in the database, I'm going to encode it as Jason. And this will receive an array and we can get the array off what was changed in the model by simply calling model get dirty. This get dirty method is going to return an associative array with the keys being the columns in the data base, in the values of what those columns have after the record was either created or updated. If the record was deleted, this will just return and empty array. Now let's turn to the hoop. Ideally, we want to know the name of the user that performed the change also its i P address. But this package could be used in projects where there is no authentication. So to account for that, let's just say we're going to store the user name in a viable cold user, which is equal to and here we're going to test first if we have a use for available. So we're going to use the off facade and called the user method, and this would return an instance of the user model. So if we have, for example, the user email or the user name, then we go ahead and use that. Otherwise we just use the word guest. But that brings another problem. What if the application this package has been used on uses a different column for the use of identification? As you can see, we can use either the name or the email in this case. But how do we know which one is being used? Well, we can offer a simple configuration file where the user who is using the package can let us know where can let the package. No, what is the column that needs to be used for identification of the user? So let's say we're going to have another column. Sorry, Another variable up here called You Sir Name column, and this will come from the configuration file so we can call scientific and it's say the configuration is stored in a fire cold activity, and this is actually a string Solis rapid between quotes. And let's say the key for the configuration is called you, sir. Name column. So now we can use the days viable here and replace it over here so that it will be dynamic . And if that wouldn't set, then we use it. Otherwise, we use guest. But now we need a way to publish this configuration file whenever the package is installed . So first, let's create a configuration file, and then we will deal with how to publish it. So here in the package folder that's creating you folder Cold, Perfect and inside it, let's creating your file called Activity, not pH. Being here, all we're going to do is to return an array off key value pairs, which will constitute our configuration. In this case is just one item called User Name column, and we're going to default that to the user name. Now, how do we publish this once the package is installed? We do that inside the service provider class, so let's open our activity service provider file and right after the migrations line, let's create a new line that says this publishes and this will take an array of resource is that we want to publish in this case, we want to publish that activity dot PHP file, which is located from this territory for this folder one level up and then inside the come thick folder, there will be the activity, not PHP file. And we want to publish this to a destination. In this case, it will be the parent project configuration file and we can no where that path is by simply using the helper function kind of thick path and within the conflict path, we're going to create a file called Activity, not PHP. And that's it. Once the package is installed, this file will be copied from the package folder into the projects Convict Bath, which will be the conflict folder in the housing project. So now that we have all of this, it saved everything the activity configuration and also the trade class, then very important. Don't forget to include this office at into the file. Using youth illuminates support for Sadd's. All right now it's time to create a new record. We have all the information that we need one. This thing we said that we wanted the i p address of the user to so I p address and we can get that from the request. So we will use the request facade and it's called the get client. I be method simple as that again. Don't forget to include this class up here. Okay, Now we have all the information we need. So let's create in your record. I'm going to use a model class that has not been created yet, but we were created in just a second, and it's called Activity Long. And in that model class, I'm going to call the create method and we will pass the user and the value comes from the user. Venerable. Next is the I P address, then the model name, the model I. D and the payload. But we are missing one column. If you remember in the table with a find a problem to say what kind of action was taken in the record either it was created, updated for the lead it. So how do we get that? Will biking or trade class? We can simply use the function name that was cold at the time of the activity and maybe we can pass that into the lock method. We can get that by referring to the function constant or magic variable SPH because it do that in all three instances and let's modify the signature up here so that would be called action. Now we can use this action when we're creating the new activity record. Now it's clean this up a little bit more. Okay, that's better. And that is basically all the trade class to us in the next video. We're going to take this straight class and use it inside our parent project, and in that way we can test its functionality. 7. 7 test: At this point, we have a package, but we want to test it locally. For us, the package already leaves inside a fully fledged lot of a project, which means that we can use this project as a testing environment. First of all, I want to configure the parent project so that I have a home page that I can look at it. Fortunately, this is very simple with Homestead. Let's go to the terminal. Note that I am not inside the virtual machine, but I am in my operating system. Inside the Home State folder, there is a file cold homestead dot Thiemo. I am going to edit that file using visual studio, but you can use any editor you want. This is a file that is used to configure many aspects off the virtual machine. For example, its i p address. How many memory doesn't use how many CP use it simulating, and the provider that is using for the digital machine down at the site section over here is where we map all of our projects to a veritable host. Make sure you have a line that says map, Home said That test, and that is mapped to home vagrant code in the name of the folder that you're using for the Packages Parent folder, and inside that folder you have to map it to the public folder. Home said That test will be the address that we use in a Web browser to access our project . Once you're done anything this file, just save it and close it and then head back to the terminal. If you made any changes to the homestead file, you need to re provision your veritable machine. You can do this by typing vagrant Reload Dash dash provision. This will reload your vehicle machine with all of the changes that you made in the homestead files. The last step to get your view toeholds up and running is to add it. Your operating system's hosts file. Since I am running on Macro is this file is located on their E. T. C hosts. But if you are on Windows, I believe the file is located on there. See Windows System 32 drivers, E T. C hosts. Oh, and I think paths on windows have back slashes instead of forward slashes. But anyway, I am running on Mac Os, so I'm going to use again coat to edit the file in Misha Studio coat, and then the path is E. T. C. Hosts. A quick note before moving forward is that you have to edit this file as an administrator. If you are running on Windows, a quick way to do that would be to look up the note pad application, then right click on it and then from note pad, open the hosts file, and you should be able to say any changes you may. So at the end of the file had a new line with the I P address off the little machine, which by the fold is 192 168 then 10 and right next to it, type the address that we mapped our project to which in this case is lateral got test. But wait, I made a mistake. The address is not ladder. Will the test? It's actually homestead, not test. I keep mixing those up. Now you can save the file and close it with all of that. We should be able to see our project in a Web browser, so let's give it a try. I'm going to use chrome as my browser. But you can use any other browser that you choose in the U. R l just type homestead, not test, and give it a go. If everything when Well, you should be able to see the fault lateral webpage To test my package. I'm going to drop it inside the use of a model. Then I can easily add authentication to this project. And with that, I'll be able to create new users. If our package works correctly, we will have a lock off all of that activity in our data, please. So let's start by modifying our users model Head back to the editor and in our parent project, open the APP folder and you should be able to see one file cold. You, sir, that PHP. This comes by default with lateral in order to start monitoring activity in this model, all we have to do is to include our trade class. So Atacama next to notifiable and then tight activity. Don't forget to add it to the file up here. Use vendor named package name and then the trade class, and that's all we have to do in the model class. Now let's go back to the terminal so that we can scaffold the authentication system. I'm going to jump into my virtual machine by using vagrant. Yes, it's a church and then jump into my project folder. Once in here, all I have to do is type partisan make south, and that's it. Lateral has scaffold it all of the authentication lateral just created the entire authentication system for us. If we go back to the browser, we can give this page a refresh, and you will notice a small change in the Oprah right corner. We have two new links, one for logging in one for register. By using the Register link, we can create new users in the system, which we can also use to logging into our application. I am already connected to the home state database, which at this point on Lee has four tables. One of them is our activity looks stable. Now Watch what happens when I create a new user in the system. Let's call him test user number one for the email address lists. Use test, add user, not one. And for the past work. Let's just use the word secret. Now I just have to confirm that retyping secret and then click register. If everything goes well, I will not only have a new user in the database, but also will have an activity log for when the user was created. But Letta Bill, once the password of at least eight characters, Seoul is just type secret. 123 That will be 123456789 Should be enough. This confirmed secret 123 looks like we have a small problem and it's because when I use the request class, I imported the wrong one. I'm supposed to be using the requests facade, but I'm actually using the http request object, which doesn't have any static method. Forget climate. So let's go ahead and salt out real quick. Back in the editor, I'm looking for the packages vendor named Package name and the trade class, which isn't the source folder. And let's fixed the import statement with illuminate support facades request that should do the trick safe back to the browser. I'm going to hit back, and I'm going to make sure that the use or did not get created in the database so that I can run this again and yeah, the user was actually created. So I'm going to delete it directly from the database. Let's go back to the browser and registered a user again. In one more problem. I did not import it. The activity log model. Let's solve that by going back to the editor and up here. Let's use activity. Look, and it's not type hinting. Let me check. Oh, of course. We did not create the model class. Fortunately, Weaken do that really quick by going back to the 10. Amino and typing Hardison make model activity. Look now, back in the editor, let's move that class from the APP folder of the parent project into our service folder. Don't forget to change the name space to the vendor name and package name, but we do have to do one more thing in this model class. If you remember in the trade, then he removed its line real quick looking down here, we're using the create method in the model, which means that we are using mass assignment to create a new record for that to work, we have to tell that a bill which of the fields in the table are allowed to be modified using mass assignment. We do that in the model class by adding a protected feel. It'll field, which is equal to an array off column names that will be allowed to be field using mass assignment. In this case, we have the yusor I p address model name model I D paid load in action. So I'm going to add all of those real quick in this array. Okay, Now I have all of the columns that are allowed for mice assignment. Let's go back to the activity trade. And now we can import the model class. So youth activity. Look, I think you don't have to use the full name space since both the trade and the model class are inside the same folder. If this is not the case, lot of it will let me know. So I'm going to say this The lead the user again from the database directly and then back in the browser, I'm going to hit back and give it another try. Well, it looks like I was wrong. Let's use the full name space for this class. Save again. Delete the user, hit back and retry Okay, That one work we created a new user in the database in latter will already logged this in automatically. Now, let's go check the database to make sure that we have an activity log record. You can see the new user here. And if we check the activity lock stable, we have a new row saying that the record was created by guest, which means that we were not logged in at the time of the activity. It's recording my I P address. It's recording the model name and I d and also the payload correctly. But there seems to be a problem with the action, and I know what the problem is. I thought by using function, I was going to capture this function name here, but I am instead capturing the closure from within. The static lock method is being called, so I guess I'm not going to be able to use this magic bearable here. That's just replace it with a literal created and down here it will be updated and delete it. Let's say that in create a new user, I'm going to look out first, then click register again and for the name. Let's call it test user number two. Email address will be test at you, sir. That, too. And then the password. Let's go check the database, and that's better. I have a new user created from the same I P and the same user, but I can clearly see the action now. Okay, I think that's enough for this video. In the next one, we're going to take our package and upload it into packages. So at this point, go to packages that work and create a new user for yourself. If you don't have one already, once you have it, go ahead and click on the next video. 8. 8 share: we are now ready to share our package with the world. What we're going to do is submit our package two packages dot org's. Once you have registered here, go ahead and logging and head to the submit section. The first thing we need to do before we submit her package it's to publish it in a repository for this example we're going to use get help again. If you don't have an account and get up, go ahead and create one Now, I've already logged in and I'm ready to create a new reports. Hitori in my account get happy is already defining me as the owner of the package. And now I just have to give it a name. The owner will be the vendor name and the package name will be the reports Hitori name in this case activity. You can give it a short description if you want. And make sure you said it as a public report story. Do not initialize it with any Read me. So leave this on checked and click on create reports Hitori did Hub will give you a quick set up so that you can initialize your project and make your first commit. We're going to follow something similar to this. So doesn't go back to the terminal and let's jump into the package folder. This is inside my render folder and then activity. No, actually, is packages vendor name, and then activity. Once inside this folder, you can initialize it would get hurt by typing. Get in it. Now, What we want to do is to add all of the files inside this folder into the repository. We can do that by typing. Get at Dash Dash. Oh, So I ran into a little problem when I tried to initialize the get hub repository for my package. So the problem was that, for some reason, get Hub was not able to add the composer there, Jason pile to the repository claiming it didn't have enough permissions to access the file . So what I had to do was to jump out of homestead and into my operating system and then access the folder of the package through the shared code folder, which, in my case, was located under my home folder, then code. And from there, the path is the same bladder building packages, then vendor, name and package name once I was in there, I simply removed the get folder by using RM for removed. Minus are for recursive since it is a folder and then dot get, which is the get hot folder. With that gone, all I had to do was to initialize it again with get in it and then did at Dash Dash. Oh, in That worked perfectly. So at this point, we have all of our files added to the reports it Terry. Now we just have to commit all of the changes we do that we get commit, bash em and then assured commit message. In this case, I'm just going to say first come in now we just have to push our code in to get help. But first we have to tell where and get help. We're going to track this coat. We call that a remote. So to have a remote to this repository, more specifically to add a remote to the master branch in the repository we type get at remote Or actually, it's the other way around. Get remote god origin and then the address of our reports. Hitori, which will be get that kid, have that come column You're get hub user name, forward slash In the name of your repository in this case, activity and then that get. And finally, to send our code in to get her, we type Get push. That's you origin, Master. Now we eustache you because we don't have a master branch in our repository yet. So the first time we push our code and we want to create a branch for it. We use bash you origin will be the remote that we just defined. And then master will be the remote branch. And then master will be the remote branch again. You don't want to use Dash you all the time on Lee the first time you want to push your code into any wretch after that, when you want to push new changes, you just have to use Get Bush. Once that's done, I'm going back to get up and refresh. And now we have our package coat on. Get up. Okay. Back to packages to submit a new package. All we have to do It's put the Earl of the Repository down here. You get here by clicking on submit, so I'm going to copy the U R L from here and put it in here and click on Chick after that. Once you have reviewed the package name, just click submit. There seems to be a problem in the former ring off the composer that Jason Fire. Specifically, it's asking for license information. Let's go ahead and fix that. Let's open the composer that Jason file for a package. And let's add the license information. Let's have it just after the minimum stability and will use the standard M. I t. License to save the file. And since we have changed the composer Jason File, we have to update this repository and get help. And since we have changed the file, we need to push this changes to get up. So in the arena, we can check for any changes by using get status. We can see that we modify the composer that Jason so this type get, uh, composer that Jason then commit or changes with kids. Come it, bash em. How did license to composer dot Jason? Then you clean the screen a little bit. Now we just have to push our changes with get course. Let's go back to packages. Click on update and now everything seems to be okay. Now, your package is ready to be imported into any lateral project. And with this we reached the end of the scores. I hope you have found the information healthful so that you can create your own packages and share your awesome ideas with the words. Thank you so much for watching and goodbye.