I have a function in a Service file called getBlendColor, something like this:
functiongetBlendColor($index):string
{
switch ($index) {
case'4':
$blendColor='bg-pink-200';
break;
case'9':
$blendColor='bg-blue-200';
break;
case'total':
$blendColor='bg-yellow-200';
break;
default:
$blendColor='';
break;
}
return$blendColor;
}
And i'm calling it inside a blade file like this:
5° Ano
But it is not working. So I put the function on the top of the blade file, and call that function, and it works. I would prefer to have that function separated, but ok. But then i change the switch to match function, to its more elegant, but de colors didn't work properly with the match function, just one color worked.
$blendColor=match ($index) {
'4'=>'bg-pink-200',
'9'=>'bg-blue-200',
'total'=>'bg-yellow-200',
default=>'',
};
So, 2 questions:
Can't we use tailwind outside blade, like in a service file and the call then in the blade file?
Why the tailwind did not work with the match funciton properly?
DL
David Lun
✓ Link copied!
Simply add a path to your php file in tailwind.config.js file, so Tailwind knows which files to look for class names. Example:
content: [
'./app/Services/**/*.php',
],
Make sure you're always using complete class names and not constructing them dynamically: Dynamic class names.
PC
Paulo Cavalcanti
✓ Link copied!
Thanks for the reply. I tried this, but it doesn't work for some how.
I tried both below and run npm run dev and npm run build:
Hello there.
I have a function in a Service file called getBlendColor, something like this:
And i'm calling it inside a blade file like this:
But it is not working. So I put the function on the top of the blade file, and call that function, and it works. I would prefer to have that function separated, but ok. But then i change the switch to match function, to its more elegant, but de colors didn't work properly with the match function, just one color worked.
So, 2 questions:
Simply add a path to your php file in
tailwind.config.jsfile, so Tailwind knows which files to look for class names. Example:Make sure you're always using complete class names and not constructing them dynamically: Dynamic class names.
Thanks for the reply. I tried this, but it doesn't work for some how. I tried both below and run npm run dev and npm run build: