[英]Laravel make arguments optional in a File
<div class="images section clearfix">
<h4>Images</h4>
{!! Form::_image("image_id", "Logo", (isset($_tournament))? $_tournament->logo : null) !!}
{!! Form::_image("image_large_id", "Large Logo", (isset($_tournament))? $_tournament->logoLarge : null) !!}
{!! Form::_image("image_square_id", "Square Logo", (isset($_tournament))? $_tournament->logoSquare : null) !!}
@endif
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-6">
<p>
{!! Form::hidden($name, null, ["id" => $name]) !!}
@if(isset($image))
<img width=100 id="{{ $name }}" src="{!! staticFileUrl('img', imagePath($image->folder, $image->filename)) !!}" />
@else
<img width=100 id="{{ $name }}" src="" />
@endif
</p>
<p>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#media_select" data-fieldname="{{ $name }}">Select {{ $display_name }}</button>
<button type="button" class="btn btn-default" id="clear-media">Clear {{ $display_name }}</button>
</p>
</div>
</div>
<script type="text/javascript">
$("button#clear-media").click(function() {
$form_element = $(this).parents("div.form-group");
$form_element.find("input#{{ $name }}").val(null);
$form_element.find("img#{{ $name }}").attr("src", "");
});
</script>
我陷入了 laravel 项目,我没有 PHP 的经验,所以我不知道要解决这个问题。 我需要为这些字段添加默认图像,我只是想知道有没有办法让所有 arguments 可选staticFileUrl('img', imagePath($image->folder, $image->filename)
可选所以我可以写类似这个staticFileUrl('img', imagePath("random string", "other random string")
?
这些已经是基于$image
model 中设置的值的变量。
如果您只需要一个默认值,请更改@else
@if(isset($image))
<img width="100" id="{{ $name }}" src="{!! staticFileUrl('img', imagePath($image->folder, $image->filename)) !!}" />
@else
<img width="100" id="{{ $name }}" src="http://www.example.org/your-image.jpg" />
@endif
如果没有图像 object,则当前不显示任何内容。 添加src
和图像将显示为默认值,除非它有图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.