search

Home  >  Q&A  >  body text

What is the difference between using a file in a class and using a file outside a class in Laravel?

Laravel What is the difference between use a file inside a calss and use a file outside a class?

For example, we often see a bunch of use after namespace, these use are outside class,
some use is in class again, what is the difference between the two?

Example: HttpControllersAuthRegisterController.php

<?php

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;



class RegisterController extends Controller
{
    use RegistersUsers;
    
   //...

}
ringa_leeringa_lee2777 days ago531

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-16 16:49:46

    Outside the class is the imported namespace, inside the class is the trait, and after the function is the variable capture.

    Documentation:

    • Use namespace: alias/import

    • Trait

    • Anonymous function

    reply
    0
  • Cancelreply