In app/Library I have a file called Helpers.php
<?php
namespace App\Library\Helpers;
class Helpers {
public function truncate($text) {
if (strlen($text) > 200) {
preg_replace('/\s+?(\S+)?$/', '', substr($text, 0, 201));
}
return $text;
}
}
In one of my views, I want to use the class:
@foreach($data['articles'] as $article)
<div class="container">
<div class="article">
<h1>{{ $article->title }}</h1>
<p>
<?php
$helpers = new \App\Library\Helpers;
echo $helpers->truncate($article->body);
?>
</p>
</div>
</div>
@endforeach
I get this error:
Class 'App\Library\Helpers' not found