Laravel is a php framework as you all know, a lite one at that. I love using it because it is very easy to learn and it save time too when using it for web development project. Laravel is one of the best php framework among others. It support mvc. It is easy to install and so on.
Laravel installation is simple. Xampp or homesteads may be used as a local server. It is recommended to use homestead when developing. Although is also ok with xampp and wamp servers.
This tutorial will help you create a simple website using laravel php framework. For this will help you understand the basic and how it work before creating complex task with the excellent framework.
We are going to used laravel 5.3 for this tutorial. Before you continue this tutorial make sure you have a little knownledge of mvc pattern
Step one to creating a basic laravel website
Let create a controller that will handle functions that will may likely used on our page
To make a controller in laravel is pretty simple using php artisan. If you using windows, Go to start->cmd-> navigate to the root of your website project (eg. Cd c:/xampp/htdocs/project). When you are there type “php artisan make:controller mycontrolller”
Once you have successfully created this controller, navigate to the folder of the laravel web project (app/http/controllers) where the controller created using php artisan is located.
Now we now have our controller ready. Lets now route the url. Routing is a method of handling all url that comes into laravel website. Whatsoever url that you link to laravel website with making available in route.php, the url will be considered invalid. When you route the url, it will take you to method in the controller you may have specified to handle the type of website page that the user will see.
Route in laravel 5.3 is located at “routes/web.php” older laravel version has it at “app/http/routes.php
web.php or routes.php
Route::get('/','Mycontroller@index');
Paste the above code in web.php as route. This means that whenever the first page of the website is visit (which is localhost/webproject/public) the method (index) which we are yet to create on my controller should handle it.
Now open myController (app/http/controller/myController) in here create a function or method that will handle the url that was entered
Public function index(){
Return view(‘index’);
}
Paste the above code on myController.php and it will return index.blade.php which we are yet to create as the html view that will be return.
now let’s create the index.blade.php. go to “resources/views/” create index.blade.php file in this folder
now run the website just by typing “localhost/project/public”
Step two creating basic laravel website
Web.php or route.php
Route::get('about','mycontroller@forAbout');
Put that code on web.php or route.php which will call on forAbout() method on myController.php controller.
myController.php
Public function forAbout(){
Return view(‘about’);
}
The above method or function in laravel will return a html page or php page normally created created in the format of blade.php.
About.blade.php
<html>
<head>
<title>the title</title>
</head>
<body>
<h1>the is the about page. Go <a href=”public”>home/</a></h1>
</body>
To test our website go to “localhost/websiteproject/about”
The about.blade.php is a view or basically a html page that will be return to the user through url. Later on the blog you will learn more about laravel framework. Hope this tutorial was helpful any complaint don’t forget to drop at the comment box.
Laravel installation is simple. Xampp or homesteads may be used as a local server. It is recommended to use homestead when developing. Although is also ok with xampp and wamp servers.
This tutorial will help you create a simple website using laravel php framework. For this will help you understand the basic and how it work before creating complex task with the excellent framework.
We are going to used laravel 5.3 for this tutorial. Before you continue this tutorial make sure you have a little knownledge of mvc pattern
Step one to creating a basic laravel website
Let create a controller that will handle functions that will may likely used on our page
To make a controller in laravel is pretty simple using php artisan. If you using windows, Go to start->cmd-> navigate to the root of your website project (eg. Cd c:/xampp/htdocs/project). When you are there type “php artisan make:controller mycontrolller”
Once you have successfully created this controller, navigate to the folder of the laravel web project (app/http/controllers) where the controller created using php artisan is located.
Now we now have our controller ready. Lets now route the url. Routing is a method of handling all url that comes into laravel website. Whatsoever url that you link to laravel website with making available in route.php, the url will be considered invalid. When you route the url, it will take you to method in the controller you may have specified to handle the type of website page that the user will see.
Route in laravel 5.3 is located at “routes/web.php” older laravel version has it at “app/http/routes.php
web.php or routes.php
Route::get('/','Mycontroller@index');
Paste the above code in web.php as route. This means that whenever the first page of the website is visit (which is localhost/webproject/public) the method (index) which we are yet to create on my controller should handle it.
Now open myController (app/http/controller/myController) in here create a function or method that will handle the url that was entered
Public function index(){
Return view(‘index’);
}
Paste the above code on myController.php and it will return index.blade.php which we are yet to create as the html view that will be return.
now let’s create the index.blade.php. go to “resources/views/” create index.blade.php file in this folder
now run the website just by typing “localhost/project/public”
Step two creating basic laravel website
Web.php or route.php
Route::get('about','mycontroller@forAbout');
Put that code on web.php or route.php which will call on forAbout() method on myController.php controller.
myController.php
Public function forAbout(){
Return view(‘about’);
}
The above method or function in laravel will return a html page or php page normally created created in the format of blade.php.
About.blade.php
<html>
<head>
<title>the title</title>
</head>
<body>
<h1>the is the about page. Go <a href=”public”>home/</a></h1>
</body>
To test our website go to “localhost/websiteproject/about”
The about.blade.php is a view or basically a html page that will be return to the user through url. Later on the blog you will learn more about laravel framework. Hope this tutorial was helpful any complaint don’t forget to drop at the comment box.
No comments:
Post a Comment