Laravel 4输入选项

Laravel 4输入选项,laravel,laravel-4,Laravel,Laravel 4,我有一个控制器代码,上面写着: $player->town_id = $input['town']; // this is located mostly in the config.lua $player->posx = '95'; // posx (X) $player->posy = '117'; // posy (Y) $player->posz = '7';

我有一个控制器代码,上面写着:

             $player->town_id = $input['town'];

         // this is located mostly in the config.lua

         $player->posx = '95';  // posx (X)
         $player->posy = '117';   // posy (Y)
         $player->posz = '7';  // posz (Z)
这里还有视图(您需要的视图的一部分):

否则,如果用户选择第二个城镇(等于2),它将使用不同的位置:

         $player->posx = '1000';  // posx (X)
         $player->posy = '1000';   // posy (Y)
         $player->posz = '7';  // posz (Z)

在这种情况下,我是否可以使用if语句或其他内容?

在控制器中,您可以使用

// Other code, assuming that $player already exists

if(Input::has('town')) {
    if(Input::get('town') == 1) {
        $player->posx = '95';
        $player->posy = '117';
        $player->posz = '7'; 
    }
    elseif(Input::get('town') == 2) {
        $player->posx = '1000';
        $player->posy = '1000';
        $player->posz = '7';
    }
}

在控制器中,您可以使用

// Other code, assuming that $player already exists

if(Input::has('town')) {
    if(Input::get('town') == 1) {
        $player->posx = '95';
        $player->posy = '117';
        $player->posz = '7'; 
    }
    elseif(Input::get('town') == 2) {
        $player->posx = '1000';
        $player->posy = '1000';
        $player->posz = '7';
    }
}

您希望将该条件(if语句)放在何处?在控制器中,查看或选择?您想在哪里使用它(如果条件)?@Rubens Mariuzzo在控制器中。您正在提交表单吗?是的,我有一个提交按钮。您想将该条件(如果语句)放在哪里?在控制器中,查看或选择?您想在哪里使用它(如果条件)?@Rubens Mariuzzo在控制器中。您正在提交表单吗?是的,我有一个提交按钮。
// Other code, assuming that $player already exists

if(Input::has('town')) {
    if(Input::get('town') == 1) {
        $player->posx = '95';
        $player->posy = '117';
        $player->posz = '7'; 
    }
    elseif(Input::get('town') == 2) {
        $player->posx = '1000';
        $player->posy = '1000';
        $player->posz = '7';
    }
}