I wanted to use an Alert trait on all my controllers so I imported it to the main Controller class (app/Http/Controllers/Controller.php). However none of my controllers could find the trait.
<?php
namespace App\Http\Controllers;
use App\Traits\Alert;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use Alert, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
This isn't how inheritance works. If you want to use it in your other controllers, you need to import it in them. And by the looks of it, your Alert trait would be better suited as some kind of service class.