Construct the Laravel Framework
Introduction:
As a programmer, we don’t need to
scratch in paper, we have tools, it will help to design our projects. Beginning to our concept, first we must know
about framework. Frameworks are software that
are developed and used by developers to build application. Let discuss with
detail,
Software Framework:
Developing
software includes coding, designing, and testing. For coding part, programmers
had to take care of the syntax, declarations, garbage collection, statements,
exceptions, and more.
Software frameworks make life easier for developers by allowing them to take control of the entire software development process, from a single platform.
Laravel:
Laravel is a PHP based web framework for building high-end web applications using its significant and graceful syntaxes. It comes with a robust collection of tools and provides application architecture. This framework is an open-source framework.
Software
needed to develop laravel projects:
- PHP
- Database (MySql).
- A localhost Web Server – Xampp, Wampp, or Mammp
- Composer – This is a dependency management software for PHP.
Procedure for downloading and install the laravel:
Step1:
Download the Xampp server and install, after that open the Xampp and start the apache and mysql server and open browser type localhost. It will load the xampp page. Look like this,
Step 2:
Now, let get into
composer, To install the composer visit https://getcomposer.org/.
Download Composer-Setup.exe - it will install the latest composer version
whenever it is executed.
To see the version of composer type composer version –v in cmd It will show the composer version.
Step 3:
Create an empty folder where the laravel folder to set up. In my convienent it is placed in F: disk.
Step 4:
After that open the visual studio code ->terminal and type,“composer global require "laravel/installer” to install the laravel in global.
Step 5:
To create a new project in laravel, type the composer create-projects laravel/laravel folder name command in terminal. It will create a new project.
To start the server use the command php artisan serve and the your localhost address is also displayed in the terminal. By using the address in browser My welcome page look like this,
Installing the Extensions in visual studio code:
Here there are some extensions available in visual studio code to make our coding easier.In vs code, Enter ctrl+shift+x, type Laravel Extension pack in serach box it will show and install it. It will include all laravel extensions like,
Laravel Artisan
Laravel Blade
Formatter
Laravel Blade Snippets
Laravel Blade spacer
Click
Explorer->open ->xampp->laravel project name->app
It will show all your
directories.
Routing:
Routing in Laravel
allows to route all our application requests to its controller.
For
creating a simple program using routes(GET ROUTES):
Click
resources->views->right click to open new file and file name with
extensions .php Store all your php files here.
For Example: File
name: sample.php
html>
<title>
sample
</title>
<body>
<h1> This
is a home page</h1>
</body>
</html>
Next click Routes->web.php to route our program .Before entering our
code into web.php run that localhost. It will dispkay the laravel home page. Because
already it has a welcome.blade.php file
Next
type our own code in web.php file
Route::get('/sample', function () {
return view('sample');
});
Run the file in local host (address of
your local host) http://127.0.0.1:8000/sample
(sample is my file name saved in view folder)
The output will be,
To start a static methods of a class scope resolution operator(::) are used.
First parameter of Routes is URI and second one is action it may be function or controller.
Sample
program for POST routes:
Step1:
Create a new file in view , save as
user_form. Type the code,
<html>
<head>Send POST Data</head>
<body>
<h1>Send User Information</h1>
<form method="post" action="<?=url('get-userdata')?>">
<label>Name:<input type="text" name="name"></label><br>
<label>Age:<input type="text" name="age"></label><br>
<label>Phone:<input type="text" name=""></label><br>
<input type="hidden" name="_token" value="<?=csrf_token()?>">
<input type="submit" value="send">
</form>
</body>
</html>
And Routes, type
Route::get('/user_form',function(){
return view('user_form');
});
Route::post('/get-userdata',function(Request $request){
dd($request->all());
});
Before run the routes file, insert
Illuminate \Http\Request.
Output will be,
Insert all the fields and click send button.
Therefore, above routes file, DD means
Dump and Die ->It will show all your data.
Comments