1
votes

I learned in php that to be able to use a namespace, you have to declare or include first.

<?php
    namespace namespace_01;

    function f1()
    {
        echo 'this is function';
    }

    use namespace_01 as test_namespace;
    test_namespace\f1();
?>

Almost all of laravel codes use namespaces. But where are they defined?

Example,

when I created a controller.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class controller1 extends Controller
{
    //
} 

where is Illuminate\Http\Request defined?

2
Set up proper IDE like PhpStorm and you will have experience boost via cmd+click on anything. Other IDE like editors (free) do the same with more configuration.Kyslik

2 Answers

4
votes

Open file from vendor/laravel/framework/src/Illuminate/Http/Request.php

There you will see the namespace declared on top as namespace Illuminate\Http; and the class name is Request

and you can see in your composer.json file

"autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },

so all the classes inside App folder are auto loaded with composer and also the vendor files. you don't need to include files every time.

2
votes

These are found in the Laravel Framework. Laravel uses composer to automatically load these packages. You can find the source in your /vendor folder, this is where composer puts the packages.