Where to make the file if i want to use this trait on my Models
How should this file look like if i want to have this trait inside:
trait FormatDates
{
Well, laravel follows PSR-4
so you should place your traits in:
app/Traits
You then need to make sure you namespace your trait with that path, so place:
namespace App\Traits;
At the top of your trait
Then make sure when you save the file, the file name matches the trait name. So, if your trait is called FormatDates
you need to save the file as FormatDates.php
Then 'use' it in your User model by adding:
use App\Traits\FormatDates;
at the top of your model, but below your namespace
and then add:
use FormatDates;
just inside the class, so for your User model, assuming you are using the laravel default, you would get:
use App\Traits\FormatDates;
class User extends Authenticatable
{
use Notifiable, FormatDates;
...
}
And remember to dump the autoloader:
composer dump-autoload