Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,016 members, 7,818,004 topics. Date: Sunday, 05 May 2024 at 03:32 AM

Learn Laravel From Scratch... - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Learn Laravel From Scratch... (2191 Views)

***hire Us For A Responsive And Functional Website (code From Scratch)*** / Tutorial: How To Create An Attractive Blog With Blogger From Scratch In 1 Hour / ###get Your Website Coded From Scratch (professional Touch On Bet/lotto/p2p Etc) (2) (3) (4)

(1) (2) (Reply) (Go Down)

Learn Laravel From Scratch... by preciousaang(m): 9:39pm On Jan 07, 2019
Hello everyone who cares. Welcome to this thread on Laravel tutorial.

2 Likes

Re: Learn Laravel From Scratch... by preciousaang(m): 9:43pm On Jan 07, 2019
First and foremost I would like to tell u about Laravel.

Laravel is a PHP framework used to build websites and Web apps . It was developed by a dude named Taylor Otwell.

grin grin

See the way I'm even saying it as if I will really start narrating story. Abeg even me self will skip it if I'm the one.

2 Likes

Re: Learn Laravel From Scratch... by preciousaang(m): 9:53pm On Jan 07, 2019
I must warn you though. Before you continue, make sure you understand PHP at least to an intermediate level. By that I mean you must understand the concept of Object Oriented programming(OOP) and MVC.

If you don't understand OOP, abeg go and learn it, if you don't understand MVC, https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller ,
read that.

It also goes without saying that you must have a good grasp of HTML and CSS. I don't know if I should say JavaScript. But hey what modern web app is built without JavaScript.

1 Like

Re: Learn Laravel From Scratch... by preciousaang(m): 10:03pm On Jan 07, 2019
Oooh lest I forget, if you have any questions or corrections fill free to ask or contribute . I'm also open to DM on 08097218247......
Well that's enough talking. Let's get into it.
Re: Learn Laravel From Scratch... by preciousaang(m): 10:16pm On Jan 07, 2019
Installing Laravel

Well the first step to installing Laravel is installing a software called composer. It is the package manager for the PHP programming language. For my brethren and sistren in the python world, composer is to PHP what 'pip' is to python. And brothers from JavaScript world. It is what NPM is to JavaScript.


Chaii too much story.



To get composer, go-to https://getcomposer.org/download/

Download and install it.

1 Like

Re: Learn Laravel From Scratch... by tuhamworld: 10:23pm On Jan 07, 2019
Let me park and secure a spot here

Re: Learn Laravel From Scratch... by preciousaang(m): 10:24pm On Jan 07, 2019
After you've done that nonsense, you need to install Laravel now.

Open you command prompt (Sorry I'm only familiar with the windows OS. Guys with Mac and Linux should please check somewhere else on installation for their own OS). Paste the code.

composer global require laravel/installer

This will install Laravel for you
Re: Learn Laravel From Scratch... by preciousaang(m): 10:30pm On Jan 07, 2019
Some people must have noticed that I didn't talk about installing PHP first. Well I assume you already have PHP installed and added to your environmental variables.

If you don't have that, I can't fit to shout

https://john-dugan.com/add-php-windows-path-variable/
Re: Learn Laravel From Scratch... by preciousaang(m): 11:02pm On Jan 07, 2019
Now the beauty of Laravel is you don't have to out it in the root folder of your local server. Hell, Apache doesn't even have to be on. Just goto the folder where you want your laravel project. Open your command prompt and navigate to that folder.


Now type: 'Laravel new site'


Where 'site' is the name of the project.

Laravel begins to download all the project files for you...

After the download is done, navigate into the site folder with cmd by typing: 'CD site'


Now type: php artisan serve

You'll get a message saying: server started locally at http:// localhost:8000



So you can open you browser now at type the address you see. Congratulations, you just installed Laravel.




Chaiiiiii too much story and English. Abeg let me sleep. We'll continue tomorrow. Please drop your comments.

Re: Learn Laravel From Scratch... by emmyw(m): 11:06pm On Jan 07, 2019
preciousaang:
I must warn you though. Before you continue, make sure you understand PHP at least to an intermediate level. By that I mean you must understand the concept of Object Oriented programming.

It also goes without saying that you must have a good grasp of HTML and CSS. I don't know if I should say JavaScript. But hey what modern web app is built without JavaScript.
I Am Very Good In php, html, css, Javascript




So Ride on Let Me See What You Gat! grin
Re: Learn Laravel From Scratch... by abdeiz(m): 9:02am On Jan 08, 2019
preciousaang:
Now the beauty of Laravel is you don't have to out it in the root folder of your local server. Hell, Apache doesn't even have to be on. Just goto the folder where you want your laravel project. Open your command prompt and navigate to that folder.


Now type: 'Laravel new site'


Where 'site' is the name of the project.

Laravel begins to download all the project files for you...

After the download is done, navigate into the site folder with cmd by typing: 'CD site'


Now type: php artisan serve

You'll get a message saying: server started locally at http:// localhost:8000



So you can open you browser now at type the address you see. Congratulations, you just installed Laravel.




Chaiiiiii too much story and English. Abeg let me sleep. We'll continue tomorrow. Please drop your comments.


Do you need Internet connection for all these installations and download?
Re: Learn Laravel From Scratch... by preciousaang(m): 2:24pm On Jan 08, 2019
abdeiz:



Do you need Internet connection for all these installations and download?

Yes, sorry for not mentioning that earlier. I can be a shitty teacher....
But here's a tip for you incase you can't be downloading fresh project everytime. Once you've downloaded a project the first time, duplicate the folder so you can reuse it when you like
Re: Learn Laravel From Scratch... by preciousaang(m): 2:26pm On Jan 08, 2019
Now that you’ve gotten Laravel installed, we can start the main stuff.

Looking inside your project folder, you will see several folders.
1. App
2. Bootstrap
3. Config
4. Database
5. Public
6. Resources
7. Routes
8. Storage
9. Tests
10. Vendors
Well, as a Nigerian, I know how impatient we can be when it comes to explaining things one by one. So I’m not going to bore you with everything. At least not now.
The folders you need to worry about for now are the routes, app and resources folder. Then we’ll look at the storage and public folder later.

Re: Learn Laravel From Scratch... by preciousaang(m): 2:29pm On Jan 08, 2019
[center]ROUTING[/center]
The first thing I will be explaining in laravel is routing.

And that has to do with routes folder in your project folder.

I don’t need explain the meaning of routes, because like I said earlier, you should understand PHP to and intermediate level.

Well, if you open your “routes folder”, you should see a file called web.php, that’s the file your want to open in your text editor. You should see something like this inside.


Route::get('/', function () {
return view('welcome');
});


Well as you can see this is a basic Laravel route. It accepts a URI, and a closure.
This is the route to the page you are currently seeing in your browser when you visit http://localhost:8000.

If you clean the whole thing and your try to reload the file, you will get a page not found error on your browser.

To create your own route, go to a new line and type:

Route::get(‘first-route’, function(){
return “This is my route”;
});

Now in your browser, goto http://localhost:8000/first-route
Voila, you get a message saying “This is my route”.
Re: Learn Laravel From Scratch... by preciousaang(m): 2:38pm On Jan 08, 2019
Please comment if you have any questions and corrections

Re: Learn Laravel From Scratch... by abdeiz(m): 2:48pm On Jan 08, 2019
preciousaang:


Yes, sorry for not mentioning that earlier. I can be a shitty teacher....
But here's a tip for you incase you can't be downloading fresh project everytime. Once you've downloaded a project the first time, duplicate the folder so you can reuse it when you like


You are doing pretty okay.

Noted.
Re: Learn Laravel From Scratch... by Julius2214(m): 5:55pm On Jan 08, 2019
I'm enjoying this... Bros com continue abeg
Re: Learn Laravel From Scratch... by preciousaang(m): 9:49pm On Jan 08, 2019
Rules for creating routes in Laravel
1. No two routes can have the same URI and the same verb.
2. No two routes can have the same name(I will have to explain this in future; For now just accept it like that).
3. Do not put space between route URI. (Of course you should know this as I assume you are familiar with PHP).
Re: Learn Laravel From Scratch... by preciousaang(m): 10:01pm On Jan 08, 2019
I know you must be asking yourself, What the hell is verb again?

Well verbs are the methods which the browser uses to send requests to the server.
The most common verbs which intermediate PHP programmers use are the POST and GET.

And I can tell you that many intermediate PHP programmers only think you use this verb when you want to submit a form.
"I used that ignorant too"....
GET
Every time you visit a page, you are making a GET request to the server. And this makes GET the most used verb on the internet.

POST and GET like I said are not the only verbs available. We have others like UPDATE, DELETE, PUT, PATCH and OPTIONS...

And Yes, we use the other verbs mostly when we want to submit forms in laravel. So Hurray, you were right.

1 Like

Re: Learn Laravel From Scratch... by preciousaang(m): 10:10pm On Jan 08, 2019
Now let's move ahead.




Now let's look in the web.php which is in the routes folder.

Let's take a look at the route that was created for use when we installed laravel.
I'm talking about the


Route::get('/', function () {
return view('welcome');
});


You'll notice that it is returning a function called view() and view has a parameter of 'welcome'.

Well view is a global function in Laravel that is used to call a view.

What is a view?
A view is the page returned to the user.
And Laravel does a superb job of helping us separate them in a different folder.
Now that brings use to the "resources"folder...


Open the "resources" folder. Under it you will see a folder called views

Under views, you'll see a file called "welcome.blade.php"
Open it in your text editor and you'll see some familiar HTML files. Well this file is the file responsible for the page you see when you visit http://localhost:8000.




Let us edit it.

On line 84, change the word "Laravel" to "Welcome To My First Laravel View"

If your server is not already on start it. And go to the homepage.


Voila, your first view.

You can edit it how ever you like.......

Re: Learn Laravel From Scratch... by abdeiz(m): 11:59am On Jan 09, 2019
We are following you bro/sis cheesy cheesy
Re: Learn Laravel From Scratch... by preciousaang(m): 3:42pm On Jan 09, 2019
You'll notice that in the screenshot I pasted, i am using port 2. i.e http://localhost:2


Don't let these confuse you. Th default port for Laravel is 8000. i.e http://localhost:8000

If you want to use a run your server in a different port,

Type: php artisan serve --port 2

Where 2 is the port number u want to use

A reason why you might want to use a different port is probably because another program might be using port 8000 or maybe port 8000 is not just responding, which is what is happening to me currently.

1 Like

Re: Learn Laravel From Scratch... by preciousaang(m): 4:53pm On Jan 10, 2019
Introduction to controllers

One awesome thing about Laravel is that it tries as much as possible to separate your HTML documents, routing, database manipulation, logic and many more other functionalities from each other for easy manipulation.
As Nick Fury told Captain America in Avengers, “IT’S IS CALLED COMPARTMENTALIZATION”.
Now one of the most vital compartments of Laravel is the “C” in MVC: Controllers.
Controllers are where the most if not all our business logic takes place. I call it business logic because that’s what guys smarter than I am call it. What can I say, I’m pretty dumb.
Steps in creating a controller
1. Navigate to your project folder using command prompt or powershell.
2. Type: php artisan make:controller FirstController where FirstController is the name of the controller.

Re: Learn Laravel From Scratch... by preciousaang(m): 4:56pm On Jan 10, 2019
That just about it. To see the controller, goto the project folder. Go into app > Http > Controllers.
There you will see the new controller that you just created.
Note: Every controller name as a matter of convention and good practice must end with the word “Controller”. Also note, I did not write firstcontroller or Firstcontroller. Writing controller names like this won’t give you any errors, but as a matter of conventions, it if required that you use camel casing. That is if you have more than one word as the name of the controller, make each of the words capital letter, then join them together. For example “test controller” becomes “TestController”, “sweet good controller” becomes “SweetGoodController”.

1 Like

Re: Learn Laravel From Scratch... by preciousaang(m): 5:52pm On Jan 10, 2019
Now that we have created our controller, let us look inside the file that was created.

As you can see inside the file laravel automatically writes somethings inside for us.
The first line tells laravel what folder the file is in. Note that they all title case.
Let us forget about the second line for now and look at the class that was created.

All we need to do in the class is create methods that we can connect routes to.
So for that we create a public method called index, and return something with it.

Re: Learn Laravel From Scratch... by preciousaang(m): 6:01pm On Jan 10, 2019
So how do we make this work? Simple. We just go to web.php which is our routes folder to link the controller method/action to a URI. We write our unique URI name as we've done before, but this time instead of writing function next, we write the name of the controller followed by an "@", then the name of our method.

1 Like

Re: Learn Laravel From Scratch... by preciousaang(m): 6:02pm On Jan 10, 2019
Please drop your comments for any question or corrections.....................
Re: Learn Laravel From Scratch... by Julius2214(m): 6:43pm On Jan 10, 2019
You're a very good teacher.... Following all the way
Re: Learn Laravel From Scratch... by preciousaang(m): 9:46pm On Jan 10, 2019
But this is very stupid way for me to introduce controller since I introduced it as a badass function of Laravel. Sorry for that. Let’s get into the fun stuff with controllers. Well remember the first route we created, where we returned a view, well we originally do that in a controller.
So let’s see how we can do that. But first let me create a folder in our views folder, you know, the folder where we keep our HTML files. Note that all files here must have the “.blade.php” extension.

So you know how I’m always calling them HTML files, well I lied. They are actually called templates.

So I’ll create a folder called frontend.

Re: Learn Laravel From Scratch... by preciousaang(m): 10:08pm On Jan 10, 2019
Note: The way we return templates. The view() function accepts “/” or “.” as means of directory separators. And the we do not add the extension of the file we are returning.
We just write the name of the file. In our case, instead of writing “frontend/index.blade.php”, we write “frontend.index”.
Because if we write it as “frontend/index.blade.php”, laravel will take frontend, index and blade as folder names and php as the name of the file we are trying access.

Re: Learn Laravel From Scratch... by preciousaang(m): 10:56pm On Jan 10, 2019
So let see some functionalities of controllers. We can pass data from controllers to views.
All we have to do in pass a second argument into the view() function. This argument should be an associative array in which the key is the name of the data and the value is the actual data being passed.

Re: Learn Laravel From Scratch... by preciousaang(m): 10:58pm On Jan 10, 2019
If it is unclear to you or you have any corrections, or you want to contribute, please comment.

(1) (2) (Reply)

Something For Shilling: Checki.com.ng / Drag N' Drop Versus Coding Of HTML / How To Make Blogger Blog Look Like A Standard Website

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 52
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.