Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
PHP - difference of use keyword outside of class and use keyword inside of a class

Good day guys!

Just want to ask the difference of use outise the class and use inside the class ? I have also googled it, but my question doesnt match an answer.

Example:

namespace App\Http\Controllers\Auth;

use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Auth;
use Illuminate\Http\Request;

class AuthController extends Controller
{

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    protected $redirectTo = '/';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
       // Some Code
    }
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When you define a class, it can only have access to other classes within its namespaces. Your controller for instance is defined within the following namespace.

namespace App\Http\Controllers\Auth;

So to use other classes, you need to import them from their own namespaces so you can access them. e.g.:

use Illuminate\Foundation\Auth\ThrottlesLogins;

If you have javascript ES6 experience, it's a little bit similar to import. When you import a package, the default namespace is /node_modules. To import your own files, you need to sort of namespace them by giving the file location like

import '../containers/index.js'

Back to Laravel. Now that you have imported the ThrottlesLogins, which is actually a trait, now inside the class you use it to expose all of the methods inside.

use Illuminate\Foundation\Auth\ThrottlesLogins; //import
public class AuthController
{
    use ThrottlesLogins; //exposes all the methods inside
    ...

    public function login()
    {
        ...
        //login failed 
        $this->incrementLoginAttempts(); //defined in ThrottlesLogins Trait
    }
}

From the example above, you have direct access to incrementLoginAttempts(), which is defined the ThrottlesLogins.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda