Laravel Hello World

After the above step, open CMD and hit the composer –version. You should receive the  Composer version information. That’s it! The setup was successful.

 

After composer installation, Write following command in command line.

After above installation, create a directory in apache24 or xamp directory, then go to command line and set your created directory.

Then write the following command into a command line.

composer createproject anvar

where, anvar is the name of the project.

Now, create your first application.

Create a controller in /app/Http/Controllers/anvar.php  and write following code in it.

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
use AppHttpControllersController;
class Anvar extends Controller
{
  /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }  
}

namespace AppHttpControllers : defines the namespace for our controller.
use IlluminateHttpRequest | use AppHttpRequests | use AppHttpControllersController : imports namespaces with the required classes to run the controller.
class Alphansotech extends Controller defines the class for the controller. The controller extends the base controller.
public function index(){ ….. } : defines the default function for the controller.

Now, navigate to app/Http/route.php and write following code.

Route::get(‘/anvar’,function(){
    return ‘Hello, This is Anvar Laravel step by step guide.’;
});

Now, open the following URL in the browser.

http://localhost/project_folder_name/public/anvar

we can also call a view file from here, to call , we need to create a view file which renders the HTML output.

Laravel uses blade template :

Blade is a default template engine of laravel.It is simple yet it has all power tools you need.To read more about blade template ,click here.

Create a file resources/views/anvar.blade.php

<!DOCTYPE html>
<html>
 <head>
 <title>Laravel</title>
 <link href=“https://fonts.googleapis.com/css?family=Lato:100” rel=“stylesheet” type=“text/css”>
 <style>
 html, body {
 height: 100%;
 }
 body {
 margin: 0;
 padding: 0;
 width: 100%;
 display: table;
 font-weight: 100;
 font-family: ‘Lato’;
 }
 .container {
 text-align: center;
 display: table-cell;
 vertical-align: middle;
 }
 .content {
 text-align: center;
 display: inline-block;
 }
 .title {
 font-size: 96px;
 }
 </style>
 </head>
 <body>
 <div class=“container”>
 <div class=“content”>
 <div class=“title”>AlphansoTech Step By Step Laravel Guide</div>
 </div>
 </div>
 </body>
</html>

 

Replace code in app/Http/route.php

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

I hope you will find this post very useful regarding Laravel beginner guide . Let me know any questions if you have in comment regarding Laravel. I will reply you ASAP.

Leave a Reply

Your email address will not be published. Required fields are marked *