簡體   English   中英

Laravel 使 arguments 在文件中成為可選

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM