在Laravel中的一个功能中显示多个视图 [英] Show Multiple views in one function in Laravel
问题描述
因此,我目前正在尝试在用户进行的每一步操作上创建一个活动日志.
So, I am currently trying to make an activity log on every single move the user makes.
class testActivityController extends Controller
{
public function index()
{
$user = Auth::user();
Activity('test-activity-controller')->log('I am inside test Activity
Controller public function index') ->causedBy($user);
$allActivities = Activity::all();
return View('admin.UsersActivityLog'->with('allActivities'),
View::testActivityview'?????);
testActivityView是我将显示文本框的地方,用户将在其中输入信息.所以我必须退货,对.
the testActivityView is where I will show the textbox where users will enter information. So I have to return it, right.
第二个是我必须显示用户进入该页面的日志,因此我必须做一些有关活动"的功能,这些功能将显示在管理员"主页面上,所有用户活动($ allActivities)都应发布在该页面上.
The second one is I have to show the log that the user went inside that page so I have to make some functions about Activities that will be shown to the main Admin page where all User Activity ($allActivities) should be posted.
如何在一个函数中返回testActivityView和UserActivityLog.
How will I be able to return the testActivityView and the UserActivityLog in one function.
非常感谢.请原谅愚蠢的命名约定.这里已经是凌晨12点了.
Thank you very much. Please forgive the stupid naming convention. It's already 12AM here.
推荐答案
您必须创建带有部分的视图,以便于重复使用.然后,您可以组成各个部分:
You have to create a view with sections for ease of re-use. It then allows you to compose the various section:
layout.blade.php
@yield('header')
@yield('body')
@yield('footer')
combined.blade.php
@extends('layouts.layout')
@section('header')
@include('header')
@stop
@section('body')
@include('body')
@stop
@section('footer')
@include('footer')
@stop
然后您从控制器调用它们;
Then you call them from controller;
function index()
{
return view('combined');
}
因此,在您的情况下,您将创建两个视图:testActivityView.blade.php
和UserActivityLog.blade.php
,您将创建这两个视图的组合,并在其上包括其他两个视图:
So in your case you create the two views: testActivityView.blade.php
and the UserActivityLog.blade.php
you create a combination of those two combined.blade.php and include the two others on it:
@extends('layouts.layout')
@section('header')
@include('header')
@stop
@section('body')
@include('testActivityView')
@include('serActivityLog')
@stop
@section('footer')
@include('footer')
@stop
然后在路径控制器上,您仅返回组合视图:return View('combined')->with(.....
then on your route controller you only return combined view: return View('combined')->with(.....
这篇关于在Laravel中的一个功能中显示多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!