如果是子域,则调用子域URL,否则在Laravel 5.7中调用域URL

时间:2019-12-30 18:38:02

标签: php laravel-5.7

如果我单击Blog按钮而不是blog.test.local,然后单击home按钮而不是test.local,那么如何检查域URL和子域URL。

class Monster extends MovingThing{
constructor(gameboard, dom_id) {
    super('monster', 20, document.getElementById(dom_id), gameboard);
}

class MovingThing {

characterType = '';
speed = 0;
dom = null;
gameBoard = null;
step = 4;
direction = 0;
gameLoop = null
size = 40;
x = 0;
y = 0;
sprite = {
    left: 0,
    right:0,
    top: 0,
    bottom: 0
};

constructor(characterType, speed, dom, gameboard) {
    this.characterType = characterType;
    this.speed = speed;
    this.dom = dom;
    this.gameBoard = gameboard;

    self = this;
    this.gameLoop = setInterval(function(){self.moveLoop()}, this.speed);
}

moveLoop(){
    if (!this.gameBoard.is_active) return;
    //if (this.characterType == 'monster') console.log(this.x, this.y)
    switch (this.direction) {
        case 37:
            this.sprite.left -= 2;
            break;
        case 40:
            this.sprite.top += 2;
            break;
        case 39:
            this.sprite.left += 2;
            break;
        case 38:
            this.sprite.top -= 2;
            break;
    }

    this.drawSprite();
     if (this.sprite.left % this.size === 0  &&
          this.sprite.top % this.size === 0  ){
        this.x = this.sprite.left / this.size;
        this.y = this.sprite.top / this.size;
        this.handleIntersection();
    }
    // console.log(this.direction)
}

setPosition(grid_x, grid_y){
    this.x = grid_x;
    this.y = grid_y;
    this.sprite.top = grid_y * this.size;
    this.sprite.left = grid_x * this.size;
    this.drawSprite();
}

drawSprite(){
    this.sprite.bottom = this.sprite.top + this.size;
    this.sprite.right = this.sprite.left + this.size;

    this.dom.style.top = this.gameBoard.gameBoardPosition.top + this.sprite.top + 'px';
    this.dom.style.left = this.gameBoard.gameBoardPosition.left +  this.sprite.left + 'px';
};

}

如果退出子域博客,则调用blog.test.local。如果我点击首页,则拨打test.local普通网址。

如何检查?我创建了中间件,但没有解决问题:

    Route::domain('{account}.test.local')->middleware('mymiddle')->group(function () {
        Route::any('/', 'Blog\BlogController@index')->name('blog');
    });

1 个答案:

答案 0 :(得分:0)

请求是从您的前端发出的。因此,如果您给用户路由提供了带有“子域” URL的路由,则无需检查您的路由中是否存在子域。

现在,如果您的用户单击一个子域,则可以根据某些内容将其重定向;应该吧

Route::any('/', 'Blog\BlogController@home')->name('home');
Route::any('/blog', 'Blog\BlogController@index')->name('blog');

Route::domain('{account}.test.local')->group(function () {
        if(Route::has('blog')){
           return redirect->route('blog');
        }else
        {
           return redirect->route('home');
        }
    });