laravel 5错误:语法错误意外'如果'在连接中间[重复]

问题描述:

This question already has an answer here:

I have this error : error : syntax error, unexpected 'if' (T_IF) when I run this code :

$output="";
        $search_iy=DB::table('iy_tkt')->where('name','LIKE','%'.$request->search.'%')
                                      ->orWhere('tkt_no','LIKE','%'.$request->search.'%')->get();
        if ($search_iy)
        {
            foreach ($search_iy as $search_iy2 ){
                        $output.='<tr>'.

                                '<td>'. strtoupper("$search_iy2->air_code").'</td>'.
                                '<td>'. strtoupper("$search_iy2->name") .'</td>'.
                                '<td>'. $search_iy2->tkt_no .

                                   if ($search_iy2->tkt_file)  
                                        '<a target="_blank" href="tkt_file/'.$search_iy2->tkt_file.'"> &nbsp; TKT </a>'.
                                         '</td>'.

                            '</tr>';  


                        }
                            return Response($output);

        }
    }

I tried to change this line to many thing :

'<td>'. $search_iy2->tkt_no .
'<td>'. $search_iy2->tkt_no ;
'<td>'. $search_iy2->tkt_no .''.

Same Error

</div>

You cannot have your if inside of setting the variable.

$output.='<tr>'.
'<td>'. strtoupper("$search_iy2->air_code").'</td>'.
'<td>'. strtoupper("$search_iy2->name") .'</td>'.
'<td>'. $search_iy2->tkt_no;

if ($search_iy2->tkt_file)  
    $output .= '<a target="_blank" href="tkt_file/'.$search_iy2->tkt_file.'"> &nbsp; TKT </a>';

$output .= '</td>';