F
F
Fragman2019-07-31 17:44:11
Laravel
Fragman, 2019-07-31 17:44:11

Why is there a 404 error when fast reloading a laravel page?

Here is the route api controller code

$game = Game::with('users')->findOrFail($request->input('gid'));
        $p1 = $game->users()->where('pnum', 1)->first();
        $p2 = $game->users()->where('pnum', 2)->first();
        if($p1 && $p2)
            return response()->json([
                'p1' => $p1->id,
                'p2' => $p2->id,
                'status' => $game->status,
            ]);
        else
            return abort(404);

The Game model defines
public function users()
    {
        return $this->belongsToMany('App\User');
    }

The connection table has additional. parameter $table->integer('pnum');
The problem is that if I quickly press F5 twice (to reload), the page gives a 404, if I just navigate to the page, it gives a normal response. How to deal with it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iAdil, 2019-08-02
@Fragman

The point is most likely in the configs
. Cache the config and routes:

php artisan config:cache
php artisan routes:cache

L
LaraLover, 2019-08-04
@LaraLover

Do you have SPA? Any vue router? It turns out that if you go through the pages, the front router works for you, if you just follow this lesson / update the pages, then the Laravel router works, but it does not have such a page. Those. if you use some kind of frontend router, you need to configure the server so that all pages are sent to the main one, and the front is already processing it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question