Let Me Teach You The PHP Laravel Framework Step By Step - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › Let Me Teach You The PHP Laravel Framework Step By Step (273 Views)
| Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 11:32am On Jun 05, 2025 |
I've noticed so many people want to learn how to build web applications from scratch. But they end up in boot camps that only teach JavaScript/NodeJS. While this JavaScript and NodeJS are cool and considered modern tools for building web applications, it's worth mentioning that PHP has seen a lot of improvements lately. In fact, PHP powers a significant percentage of websites or web applications online today. One of such typical examples is WordPress, a very powerful content management system you can use to build just about any kind of website. Laravel, a PHP framework is very powerful framework that makes building web applications a piece of cake if only you understand the basics of HTML, PHP and maybe some database management tools like MYSQL. In this thread, I will try to introduce Laravel to you in very simple terms. Once you grasp the basics of what I'll say here, getting started with actually using Laravel will be easier than you thought. 😉 Let's delve in!! 🙌🙌
|
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 11:39am On Jun 05, 2025 |
First things first, Laravel is just a PHP framework that abstracts (or removes) the difficulty/complexity involved in using plain (vanilla) PHP when building web applications. For example, if using a normal saw blade to cut through wood makes you sweat, using a machine saw will be easier. So in this case, the hand saw is plain PHP, while the machine/mechanical saw is a PHP framework such as Laravel. When you know what you are doing, using a framework like Laravel in your project is like cutting through butter with a hot knife.😉😉 It cuts through easily. If that's clear let's move on. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 11:43am On Jun 05, 2025 |
Next up, let's talk about the basic architecture that Laravel uses. Laravel is built using the MVC architecture. Don't worry, it's not difficult at all. Let me explain it. 😊😊 First, by architecture, we don't mean it was drawn by an architect using the pencil and white paper. Nope! By MVC architecture, we mean it's just a style or pattern that the framework follows. So, when building your applications on that framework, it must follow that pattern. But what is MVC?? |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 11:48am On Jun 05, 2025*. Modified: 12:06pm On Jun 05, 2025 |
MVC stands for Model, View and Controller. Let's explain each one. Model : This guy handles everything related to data storage and retrieval. Yes! If you want to build an awesome project that stores information somewhere (somewhere == database), then you simply need to engage the services of a model. For example, if I want to create an e-commerce application, then I will need to store my products somewhere. I will also need to store my customers somewhere. How about their reviews of my projects? Yes, I can store that too. It is the model that helps me do that! But what does the V stand for in MVC? Lets see that one next! |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 11:53am On Jun 05, 2025 |
Okay! The V in MVC doesn't stand for vehicle! Nope! It stands for View. Yes, View!!! Every web application needs to present data to visitors or users (let's use users 😉). That data could be static data or dynamic data that is fetched from the database (handled by the Model). See, if your application doesn't present data, it is useless. Nobody wants to see blanck pages. So, your View shows your users something. It could be your products, your customers, your customer reviews, your stories or just anything. So anytime you want to present something, just feel free to create a View and show your data there! Easy right? But how about the C in MVC? What does it stand for?? |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by NNtv(m): 12:01pm On Jun 05, 2025 |
Interesting |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:01pm On Jun 05, 2025 |
Now, the C in MVC stands for Coffee ☕! Ohh, sorry, it stands for Controller! 😊😊 Think of the Controller as the main engine of your web application. It handles the logic of what the user should be shown anytime they make a request to a certain part of your project. The Controller is just like a messenger that listens to his/her boss. When they messenger gets instructions from their boss, they act based on that instruction. If the instruction is not clear, the messenger won't know what to do. But if the instruction is clear, the messenger does exactly what's required. That's is how the Controller is. If a user makes a request to view another user's profile, it's an instruction to your application. In this case, it is the responsibility of your Controller to process that request and if it is successful, present the result to the screen! That's basically it for MVC! |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:14pm On Jun 05, 2025 |
Now that we know what MVC stands for and what it is all about, let's picture how we can apply this knowledge at least in theory. Let's say we want to build a forum like Nairaland. A basic version of it of course. 😊 In this situation, we need to be clear about what we want. So let's see. 1. We want users to register 2. We want users to be able to login 3. We want to have categories/sections 3. We want users to be able to create topics in a particular section/category 4. We want to store the topics that users created. 5. We want people to view the created topics by clicking on them. Simple right? Let's see the Laravel Models that will be needed for this project as well as the Views as well as the Controllers we will be needing. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by RealityKings1: 12:20pm On Jun 05, 2025 |
Following |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:20pm On Jun 05, 2025 |
First, since people will be able to register, that means we need to store their information somewhere. Remember, our "somewhere" is called the database. The first Model we will need is the User model to store users of our forum. The second model we will need is Category model to store categories/sections of our forum. The third and final model we will need is, guess it! Yeah, you got it. We will need the Topic model. So the three models are User, Category and Topic. Notice I didn't pluralize the model names. That's a convention in Laravel. Model names should be written in singular form. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:30pm On Jun 05, 2025 |
Now that we have seen the models that will be needed for our Forum project, what about the Views?? Well, we will need 6 different views. Here: 1. register : This guy presents the registration form that the user should fill in order to register. 2. login: This guys displays the login form. 3. create-topic: This guy presents another form for a user to create a new topic after they have logged in successfully. 4. list-topics: This one presents a nice list of all created topics in our forum. 5. create-category: This will help create new category/section. 6. show-single-topic: This will finally help us to view a single topic and read it's content. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:46pm On Jun 05, 2025*. Modified: 4:05pm On Jun 06, 2025 |
Finally, let's talk about the required Controller files. Well, we can use just one Controller file. But the controller will contain multiple methods (call them functions) and each function handles a particular/specific task such as displaying a form, showing a topic, etc. For our case, let's call the Controller ForumController. Now, inside this controller class we can have the following methods: 1. register() 2.login() 3. create_topic() 4. create_category() 5. list_topics() 6. show_single_topic(identifier) The bodies of these 6 methods above will handle the logical aspect of our project. Let's explain each |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 12:49pm On Jun 05, 2025*. Modified: 4:07pm On Jun 06, 2025 |
As you can see above, in simple terms, the register() method will handle user registration logic. The login() method will check if the details the user entered are correct or not. If correct, the user will be logged in, otherwise, the user will be denied access. The create_topic() method will handle the logic of creating a new topic and storing it using the associated Model. The create_category() will handle creating and storing new forum categories. The list_topics() method will handle fetching all existing topics created by users. The show_single_post(identifier) method will handle fetching a single topic based on the identifier that has been passed to it. That's it! |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 2:14pm On Jun 05, 2025*. Modified: 4:29pm On Jun 05, 2025 |
To learn more, let's talk through a direct message. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by Emeka71(m): 2:18pm On Jun 06, 2025 |
DevLaive:Nice information. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by Oseniade(m): 10:12pm On Jun 08, 2025 |
Good intro. How I wish you would continue here but it is what it is. |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by fnep2smooth(m): 4:45am On Jun 09, 2025 |
You need to teach them how to run artisan command for easy setup of somethings. Nice one |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 8:51am On Jun 09, 2025 |
fnep2smooth:Yeah. You're right. But Artisan commands are outside the scope of this theoretical introduction to Laravel. 😊😊 |
| Re: Let Me Teach You The PHP Laravel Framework Step By Step by DevLaive(op): 8:52am On Jun 09, 2025 |
Oseniade:You can learn directly from me. Distance isn't an issue. 😊 |
Php/ Laravel Web Developer Needed • Limited! Let Me Teach You How To Earn Over 20k Daily As An Affiliate Marketer • Easy Steps To Change The PHP Version Used On Your Account • 2 • 3 • 4
SEO Benefits Of Explainer Videos: How An Agency Can Improve Your Rankings Introd • Shopify Account Available For Sale • Hiring: Facebook Page Manager For Trendonaija — Grow A Viral Brand With Us!