X

    Get a Quote

    How Laravel Framework works?

    654 views
    Amit Shukla

    Maybe pulling out a few highlights of what separates Laravel Framework from other frameworks in the space. You’ve already called out community and emphasis on the individual Laravel developer, anything else?

    See how it works

    Up until now, everything I’ve shared here has been entirely abstract. What about the
    code, you ask? Let’s dig into a simple application so you can see what working with
    Laravel day-to-day is actually like.

    Let’s look at

    Hello, World
    .
    Example 1-1. “Hello, World” in routes.php

    // File: app/Http/routes.php

    < ?php
    Route
    ::get(‘/’, function() {
    return
    ‘Hello, World!’
    ;
    });

    If you initialize a brand new Laravel application on your machine, edit the

    app/Http/routes.php file and make it look like the preceding example, and then serve the site from the public directory, you’ll have a fully functioning

    Hello, World

    Example:

    It looks very similar to do the same with controllers:

    Example 1-2. “Hello, World” with controllers

    // File: app/Http/routes.php
    < ?php
    Route
    ::get(‘/’, ‘WelcomeController@index’);
    // File: app/Http/Controllers/WelcomeController.php
    namespaceapp\Http\Controllers;

    class WelcomeController
    {
    public function index()
    {
    return 'Hello, World!';
    }
    }

    And if we’re storing our greetings in the database, it’ll also look pretty similar (see
    Example 1-3).
    Example 1-3. Multi-greeting “Hello, World” with database access

    // File: app/Http/routes.php
    < ?php Route::get('/', function() { returnGreeting::first()->greeting_text;
    });


    // File: app/Greeting.php

    < ?PHP

    use Illuminate\Database\Eloquent\Model;
    class Bio extends Model
    {
    protected
    $table = ‘greetings’;
    }

    // File: database/migrations/2015_07_19_010000_create_greetings_table.php

    < ?php
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;

    class CreateGreetingsTable extends Migration
    {
    public function up()
    {
    Schema::create('greetings', function (Blueprint $table) {
    $table->increments('id');
    $table->string('greeting_text');
    $table->timestamps();
    });
    }

    public function down()
    {
    Schema::drop('greetings'
    );
    }
    }

    few lines of code, we’ve set up database migrations and models and pulled records
    out. It’s just that simple.

    Avatar for Amit
    The Author
    Amit Shukla
    Director of NBT
    Amit Shukla is the Director of Next Big Technology, a leading IT consulting company. With a profound passion for staying updated on the latest trends and technologies across various domains, Amit is a dedicated entrepreneur in the IT sector. He takes it upon himself to enlighten his audience with the most current market trends and innovations. His commitment to keeping the industry informed is a testament to his role as a visionary leader in the world of technology.