Roots Discourse

Fatal error: Trait not found (but works fine on localhost) (SOLVED)

Having a controller issue here.

I added a trait to the FrontPage controller and it’s working fine on the localhost but I get a “Trait not found” error on the production server.

app\Controllers\FrontPage.php :

<?php

namespace App\Controllers;

use Sober\Controller\Controller;

class FrontPage extends Controller
{
  use Partials\ACF\Hero;
}

app\Controllers\Partials\ACF\hero.php :

<?php

namespace App\Controllers\Partials\ACF;

trait Hero
{
    public function hero()      
    {
      $description = get_field('hero_page_description');
      $image = get_field('hero_page_image');
      
      return (object) array(
        'description' => $description,
        'image' => $image
      ); 
    }
}

Am i missing something?

Try renaming hero.php to Hero.php, then $ composer dumpautoload. PSR4 autoloaders are case-sensitive.

Thank you TangRufus! It’s now working on both localhost and production environment. :+1:

This topic was automatically closed after 42 days. New replies are no longer allowed.