1

I am using a package called chatter and managed to include it in my own post. Now I have a table called games, and every time I create a new game, I also add a chatter discussion. That works.

So, on the single game page, I load the details of the game and the chatter discussions as an iframe. Meaning that now I have an HTML inside an HTML. Users are now able to use chatter discussions.

The controller looks pretty much like this:

public function show(Game $game)
{
    // We know this is a game
    // Get the category first
    $category = DB::table('chatter_categories')->whereName('Game')->first();

    // Get the discussion
    // A discussion has many post(s)
    $discussion = DB::table('chatter_discussion')->whereChatterCategoryId($category->id)->first();
                                             //dd($chatter_post);
    return view('games.games', ['game' => $game, 'discussion' => $discussion, 'category' => $category]);
}

Now, in my games.blade I have the following:

<article id="discussion">
    <iframe id="myiframe" src="/forums/discussion/{{ $category->slug }}/{{ $discussion->slug }}" style="height: 800px; width: 100%;" frameborder="0" />
</article>

Chatter default page comes with a header and looks like in the image below:

enter image description here

If I view a game that I create, I also see the chatter discussions for that games as expected:

enter image description here

Question: How can I remove the header section of the chatter discussion only on the games page?

If I simply target the header id directly

div#chatter_header{ 
    display: none;
}

It will remove the heading, but that will also go away if I visit chatter original front end view.

This is when I thought of checking the current page URL and the styling accordingly, but this does not work.

My route for the games look like this:

Route::resource('games', 'GameController');
halfer
  • 19,824
  • 17
  • 99
  • 186
Sidney Sousa
  • 3,378
  • 11
  • 48
  • 99

3 Answers3

3

If you use Laravel, you can do this with URL query parameters:

if ($request->has('forums')) {
    // do stuff here
}

See https://laravel.com/docs/5.7/requests#retrieving-input

In your template, you can use:

@if(app('request')->input('forums'))
   <span>Do stuff</span>
@endif 

See: Lumen: get URL parameter in a Blade view

hktang
  • 1,745
  • 21
  • 35
2

You can try -

$parse = parse_url('http://domain.local/forums/discussion/game/sidney-game', PHP_URL_PATH);

if (strpos($parse, '/forums/') === 0) {
  // do what needed
}

It will check if the path starts with forums.

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

Try something like this:

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsedURL = parse_url($actual_link);
parse_str($parsedURL['forums'], $parts);
echo $query['forums'];