如何在视图laravel刀片上添加类中的操作符三元组?

I try like this :

@for($i = 0; $i < 5; $i++) 
...
    <div class="image ($i==0) ? 'image-main' : ''">
...
@endfor

But it does not work.

It seems the way of writing is incorrect.

How can I solve this problem?

In laravel's blade file you need to use {{}} to execute php code.

{{ ($i == 0) ? 'image-main' : '' }}

You need to use {{ }}

@for($i = 0; $i < 5; $i++)
    ...
    <div class="image {{ ($i==0) ? 'image-main' : '' }}">
    ...
@endfor
<div class="{{ ($i == 0) ? 'image-main' : '' }}"></div>

try with this,

@for($i = 0; $i < 5; $i++) 
    <div class="image{{ ($i==0) ? 'image-main' : '' }}">
@endfor