[英]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>
I got a thrown into a laravel project and I have no experience in PHP so I have no idea to fix this.我陷入了 laravel 项目,我没有 PHP 的经验,所以我不知道要解决这个问题。 I need to add a default image for these fields and I just wonder is there a way to make all arguments optional staticFileUrl('img', imagePath($image->folder, $image->filename)
optional so I can write something like this staticFileUrl('img', imagePath("random string", "other random string")
?我需要为这些字段添加默认图像,我只是想知道有没有办法让所有 arguments 可选staticFileUrl('img', imagePath($image->folder, $image->filename)
可选所以我可以写类似这个staticFileUrl('img', imagePath("random string", "other random string")
?
Those already are variables based on the values set in the $image
model.这些已经是基于$image
model 中设置的值的变量。
If all you need is a default, change the @else
如果您只需要一个默认值,请更改@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
It currently displays nothing if there is no image object.如果没有图像 object,则当前不显示任何内容。 Adding the src
and an image will display that as your default unless it has an image.添加src
和图像将显示为默认值,除非它有图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.