【问题标题】:Open Modal from another page Laravel从另一个页面 Laravel 打开 Modal
【发布时间】:2018-11-08 22:52:13
【问题描述】:

我在 laravel 项目上工作,我有许多将在我的项目中使用的模态,所以我决定将模态代码放在另一个文件夹中。 我的视图代码是

<button type="button" class="btn btn-success"  data-toggle="modal" data- 
 target="#AddUserMoodal"><i class="fa fa-edit" aria-hidden="true"></i> 

当我按下此按钮时,我想打开 modals 文件夹中的 AddModal 这是 /modals/addmodal.blade.php 的代码

 <div id="addModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"></h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="control-label col-sm-2" for="title">Title:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="title_add" autofocus>
                            <small>Min: 2, Max: 32, only text</small>
                            <p class="errorTitle text-center alert alert-danger hidden"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2" for="content">Content:</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="content_add" cols="40" rows="5"></textarea>
                            <small>Min: 2, Max: 128, only text</small>
                            <p class="errorContent text-center alert alert-danger hidden"></p>
                        </div>
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success add" data-dismiss="modal">
                        <span id="" class='glyphicon glyphicon-check'></span> Add
                    </button>
                    <button type="button" class="btn btn-warning" data-dismiss="modal">
                        <span class='glyphicon glyphicon-remove'></span> Close
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

但我不知道该怎么做。它的路线是什么

【问题讨论】:

  • 如果您的代码/组件在文件夹/resources/views/modals/addmodal.blade.php 中,您可以通过@include('modals.addmodal')@component('modals.addmodal') 访问它

标签: php html laravel modal-dialog bootstrap-4


【解决方案1】:

看看@include directive

旁注:

仅供参考,回到旧的 Laravel 你可以这样解决它:

// routes.php (which is web.php now)
Route::get('view-component/{name}', function ($name) {
    return view($name);
});

// In your view
{{ route('view-component/user-form') }}

【讨论】:

    【解决方案2】:

    你只需要包含你的刀片文件

    @include('path.to.your.blade')

    您可以将您的 HTML 结构分成几部分,然后像上面一样包含它们。

    查看刀片的 Laravel 文档:https://laravel.com/docs/5.6/blade#including-sub-views

    【讨论】:

      【解决方案3】:

      假设你在主页:home.blade.php,使用include

      <body>
      
          @include('models/addmodal')
      
      </body>
      

      如果您的模态是动态的,并且您想将数据传递给模态:

      <body>
      
         @include('models/addmodal',['title'=>$title,'data'=>$data])
      
      </body>
      

      并在您的添加模式中

      <div id="addModal" class="modal fade" role="dialog">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                    {{$title}}
                  </div>
              </div>
           </div>
      </div>
      

      【讨论】:

      • 这是modals/,而不是models/
      猜你喜欢
      • 2013-10-31
      • 2011-01-12
      • 2011-04-06
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多