javascript - 有没有办法用 php 检查 url 中的特定参数?

标签 javascript php jquery laravel

我正在使用一个名为chatter的包,并设法将其包含在我自己的帖子中。 现在我有一个名为 games 的表,每次创建新游戏时,我还会添加一个喋喋不休的讨论。这有效。

因此,在单个游戏页面上,我将游戏的详细信息和聊天讨论加载为 iframe。这意味着现在我在 HTML 中包含了 HTML。 用户现在可以使用聊天讨论。

Controller 看起来非常像这样:

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

现在,在我的 games.blade 中,我有以下内容:

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

Chatter 默认页面带有标题,如下图所示:

enter image description here

如果我查看自己创建的游戏,我还会按预期看到该游戏的聊天讨论:

enter image description here

问题:如何删除仅在游戏页面上的聊天讨论的标题部分?

如果我只是直接定位 header ID

div#chatter_header{ 
    display: none;
}

它将删除标题,但如果我访问chatter原始前端 View ,标题也会消失。

此时我想到检查当前页面 URL 和相应的样式,但这不起作用。

我的游戏路线如下:

Route::resource('games', 'GameController');

最佳答案

如果你使用 Laravel,你可以使用 URL 查询参数来做到这一点:

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

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

在您的模板中,您可以使用:

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

参见:Lumen: get URL parameter in a Blade view

关于javascript - 有没有办法用 php 检查 url 中的特定参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53628213/

相关文章:

javascript - jQuery ajax 无法检索 json

php - Ajax post 请求作为空对象被接收

javascript - 当某些像素进入视口(viewport)时动画(Pen by Bramus)

javascript - 在 Vuex 中存储 Fabric.js Canvas 引用 - [vuex] 不要在突变处理程序之外改变 vuex 存储状态

javascript - 使用较短的数据库查询代码将数据插入 MySQL 数据库表

php - 捕获特定表单的按钮点击事件?

php - 选择连接表 A 和表 B,同时根据表 A 的外键显示表 B 项目

javascript - 使用 Javascript 或 Jquery 附加 Html

javascript - 将 jQuery 存储在一个变量中然后提醒它

javascript - jQuery Toggle -- 我做错了什么?