Search code examples
laravellaravel-5.3

Identifying from which method it is coming


I have two methods both returning the view:

public function method1()
{
  return ('view1');
}

and

public function method2()
{
  return ('view1');
}

In the view i want to edit some changes regarding from which method it is coming:

Something like this in view1:

@if(coming form method1)
{
   This is coming from method1,
}
@endif

How can this be acheived? Currently i'm just making two separate views for so minor change.


Solution

  • Why not add a flag in method

    public function method1()
    {
      $flag = 'method1';
      return ('view1', compact('flag'));
    }
    
    public function method2()
    {
      $flag = 'method2';
      return ('view1', compact('flag'));
    }
    

    and in the view check for the flag

    @if ($flag == 'method1')
       This is coming from method1
    @elseif ($flag == 'method2')
       This is coming from method2
    @endif