I'm attempting to create a custom member tag for my forum that will display "X Years of Experience" but with different colors for each individual year, such as red for year one, blue for year two, and so forth.
Getting the date difference was simple enough but I'm stumped on the next bit.
This is the code I currently have:
{{$joinDate = $comment->author()->get_joined(); $currentDate = new \DateTime(); $interval = $joinDate->diff($currentDate); $experience = \IPS\DateTime::formatInterval($interval, 1);}}
<li class="ipsType_light">{$experience} {lang="memberexperience_experience"}</li>
I am just trying to give you an idea.
You should create styles.php file in your config folder. And add this below code into this file.
return [
'experience' => [
1 => 'danger',
2 => 'secondary',
3 => 'primary'
]
];
Then in your blade file write this code
<li class="text-{{config("styles.experience.$experience")}}">{{$experience}} {{lang="memberexperience_experience"}}</li>
If experience is possible to less than 1 year then use below code
@if($experience < 1)
<li class="text-danger">{{$experience}}</li>
@else
<li class="text-{{config("styles.experience.$experience")}}">
{{$experience}}{{lang="memberexperience_experience"}}</li>
@endif
Hope this will give you an idea and help you.