R
R
Rishat Sultanov2017-05-10 16:38:17
Laravel
Rishat Sultanov, 2017-05-10 16:38:17

How not to follow a route but complete it?

Good afternoon gentlemen :)
There are 4 buttons

<div class="ramka">
    <h2>Управление виртуальной жизнью</h2>
    </br>
    <div class="ramkaleft">
    </br>
        <form action="/startvirtuallive" method="get">
            <button type="submit" class="btn btn-success">Запустить рождаемость</button>
        </form>
        </br>
        <form action="/startvirtuallivekiller" method="get">
            <button type="submit" class="btn btn-success">Запустить смертность</button>
        </form>
    </div>
    <div class="ramkaright">
        </br>
        <form action="/stopvirtuallive" method="get">
            <button type="submit" class="btn btn-danger">Остановить рождаемость</button>
        </form>
        </br>
        <form action="/stopvirtuallivekiller" method="get">
            <button type="submit" class="btn btn-danger">Остановить смертность</button>
        </form>
    </div>

that operate on these routes:
Route::get('/startvirtuallive', '[email protected]');
Route::get('/startvirtuallivekiller', '[email protected]');
Route::get('/stopvirtuallive', '[email protected]');
Route::get('/stopvirtuallivekiller', '[email protected]');

The first two routes work and do not run a blank page on this route, and routes 3 and 4 open a new blank page. On the same page..
UPD
Methods in the controller:
class MainController extends Controller
{
    public function startvirtuallive()
    {
        $this->virtuallive(true);

    }
    public function startvirtuallivekiller()
    {
        $this->virtuallivekiller(true);

    }

    public function stopvirtuallive()
    {
        $this->virtuallive(false);

    }
    public function stopvirtuallivekiller()
    {
        $this->virtuallivekiller(false);

    }
    public function virtuallivekiller($virtual_livekiller = true)
    {
        if ($virtual_livekiller != false)
        {
            DB::table('virtuallive')
                ->where('id', 1)
                ->update(['livekiller' => 1]);
        }
        if ($virtual_livekiller != true)
        {
            DB::table('virtuallive')
                ->where('id', 1)
                ->update(['livekiller' => 0]);
        }
        while ($virtual_livekiller == true)
        {
            $live = DB::table('virtuallive')->get();
            foreach($live as $animal)
            {
                $now = $animal->livekiller;
            }
            if($now == 1)
            {
                DB::select('CALL fixid();');
                if(DB::table('zagon_all')->where('id', '=', 1)->delete() == true)
                {

                    DB::table('zagon_dead')->insert(
                        ['idanimal' => 1]
                    );
                    DB::select('CALL fixid();');
                }
                sleep(1);
            }
            else
                {
                    break;
                }

        }
    }
    public function virtuallive($virtual_live = true)
    {
        if ($virtual_live != false)
        {
            DB::table('virtuallive')
                ->where('id', 1)
                ->update(['live' => 1]);
        }
        if ($virtual_live != true)
        {
            DB::table('virtuallive')
                ->where('id', 1)
                ->update(['live' => 0]);
        }
        while ($virtual_live == true) {
            $live = DB::table('virtuallive')->get();
            foreach($live as $animal)
            {
                $now = $animal->live;
            }
            if($now == 1){
            DB::table('zagon_all')-> insertGetId(
                []
            );
            DB::select('CALL fixid();');
            sleep(10);
            }
            else
            {
                break;
            }

        }
    }
}

What is the problem?

I recorded a video where I visually showed what the problem is:
https://www.youtube.com/watch?v=f2Fuy9If3gE&featur...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ajaxtelamonid, 2017-05-11
@rishatss

The fact that nothing is shown on the page is correct, you have it written that nothing should be shown. To show it, you need to do return view(...) , and in your controllers you only have a method call and that's it.
The first two methods also do not return anything, it's just that in them your code loops on while ($virtual_live == true), no new content comes to the page, and it seems that the page has been redrawn. In fact, it's just that the http request is not over yet - pay attention to the chrome twist in the tab.
You need to do return reditect(...) on the page that draws the original image.

V
vism, 2017-05-11
@vism

Generally.
This is a troll question. HE does not even want to learn the basics of the basics and read the manuals, and he spams everything on the toaster every day with very stupid questions.
Don't get fooled. :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question