1. When the page accesses the blad template page, the variable is undefined.
2. Code
<p>
<form method="POST" action="importexcel" enctype="multipart/form-data">
<input type="file" name="myfile" /><br/>
<input type="submit" name="submit" value="提交" />
</form>
</p>
@if($flag_result == true)
<p style="color:darkgreen;margin-top:5px;">
导入数据成功
</p>
@endif
@if(!($fileType == 'xlsx'))
<p style="color:red;margin-top:5px;">
数据不合法
</p>
@endif
</p>
3. It will prompt Undefined variable: flag_result
4. How to solve it?
PS: You can return view('importexcel',compact('flag_result','fileType')); in the control layer. I enter this view first. Then, submit the data into the controller and return to the page.
Then the question is, is $flag_result defined in the controller? Take a screenshot to see
When you enter for the first time, you set it, and then when you submit the data and enter the controller, do you also set these two variables when you return to this view again?