我正在开发laravel项目,我将在项目中使用很多模态,所以我决定将模态代码放在另一个文件夹中。 我的观点代码是
<button type="button" class="btn btn-success" data-toggle="modal" data-
target="#AddUserMoodal"><i class="fa fa-edit" aria-hidden="true"></i>
当我按下此按钮时,我想打开位于模态文件夹中的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">×</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>
但我不知道该怎么做。路线将是什么
答案 0 :(得分:1)
旁注:
仅供参考,回到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') }}
答案 1 :(得分:1)
假设您在主页:home.blade.php
,请使用include
<body>
@include('models/addmodal')
</body>
如果您的模态是动态的,并且您想将数据传递给模态:
<body>
@include('models/addmodal',['title'=>$title,'data'=>$data])
</body>
并在你的addmodel中
<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>
答案 2 :(得分:0)
您只需要包含刀片文件
@include('path.to.your.blade')
您可以将HTML结构分成几部分,并按上述方式包含它们。
检查刀片的Laravel文档:https://laravel.com/docs/5.6/blade#including-sub-views