Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

A trait is similar to classes but it cannot be instantiated. Traits can have multiple methods which can be used in multiple classes.

Traits in Laravel

Traits can be placed inside app/Traits folder in laravel. You can create your traits inside here with proper namespace. Here is an example of creating a trait class. I have create a trait like this app\Traits\StorageTrait.php


namespace App\Traits;

use Illuminate\Support\Facades\Storage;

trait StorageTrait {

     * @param $image
     * @return 
     * Delete file from public storage
    public function deleteFromPublic($image)
        // Delete code here

Once trait is in place, don’t forget to dump autoload. (composer dump-autoload)

Here is a way you can use this trait in your controller (or model)


namespace App\Http\Controllers;

use App\Traits\StorageTrait;

class UserController extends Controller

    use StorageTrait;

    public function destroy(User $user)
        // Delete user profile image using our trait
        if($user->picture) {

        // Delete user

        return redirect()->route('user.index')->withStatus(__('User successfully deleted.'));