SO YOU DO SYMFONY BUT WANT TO DO LARAVEL

It's widely known Laravel was built using Symfony so a lot of people say it's really easy to make the jump. But then again a lot of people believe in Santa…

Apr 25th 2018
background

Never mind! In any case, I decided to give it a try and bought the really nice (AKA cheap) Build Wordpress CMS Clone with Laravel 5 tutorial from a very well-known website.

The first thing you need to know about Laravel (when you come from Symfony) is that Laravel was embedded in a lot of voodoo, witchcraft, black magic and other very mysterious occult things. Which is not necessarily bad, on the contrary. Summing the right spell, it's really fast to do stuff.

 

My first controller

The first thing you need to know is that Laravel uses the Blade template engine, which is vaguely similar to Symfony's Twig. So let's create our first template (named do.blade.php) in the resources/views/ folder.

<b>My thing is</b>: {{ $myThing }}

 

The second thing you need to know is that Laravel won't use bundles (in the same way Symfony started to do from version 4). So, let's create a controller with the artisan make:controller DoSomethingController command, and add the DoSomethingController::do() method as shown below:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DoSomethingController extends Controller
{
    public function do()
    {
        return view('do', ['myThing' => 'Laravel']);
    }
}

 

And now, let's define a route for the method in the routes/web.php file.

<?php
Route::get(
    '/do',
    ['uses' => '[email protected]', 'as' => 'do_something_do']
);

 

Now, just open the route in your development url (AKA http::/localhost/do) and you will see the lovely output:

My thing is: Laravel

 

Black Magic

If you know one or two things about PHP, you won't remember to have seen the view function anywhere in the PHP Language Reference manual... but don't pull your hair off yet. Check the Laravel helpers reference first.

Laravel includes a variety of global "helper" PHP functions.

Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

That's right. There are more functions in Laravel and PHP, Horatio, than are dreamt of in your philosophy.

 

Is it a bird? Is it a plane? No! It's a facade!!!

And you will also notice that there is no use clause to import any Route namespace, yet you are using it.

Somebody may think that Laravel is Namespace aware (whatever that means) but it's not. This is just a facade, (The C reads as SS) what the dictionary defines as a "deceptive outward appearance" and what, in truth, it is.

Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades which provide access to almost all of Laravel's features. Laravel facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

All of Laravel's facades are defined in the Illuminate\Support\Facades namespace.

And you will use facades a lot if you expect to work with Laravel.

 

To Infinity and Beyond

There is much more to say about starting with Laravel, but this is just an article, not a book. But fear not young Padawan, soon enough there will be other articles about weird stuff in the Laravel universe.

And may the Force be with you.

 

Written by Eduardo Fernandes | Developer at Cleverti

background

Letsgo-on at cebit 2016 via cleverti

Back to News.. Next Article