phplaravelcontrollerviewactivitylog

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

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.


Solution

  • 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(.....