Show Multiple views in one function in Laravel

我们两清 提交于 2019-12-12 05:59:45

问题


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'?????);

the testActivityView is where I will show the textbox where users will enter information. So I have to return it, right.

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.

How will I be able to return the testActivityView and the UserActivityLog in one function.

Thank you very much. Please forgive the stupid naming convention. It's already 12AM here.


回答1:


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');
}

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

then on your route controller you only return combined view: return View('combined')->with(.....



来源:https://stackoverflow.com/questions/45016625/show-multiple-views-in-one-function-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!