[Vuejs]-How To prevent forms from working in Laravel?

0👍

Consider the @Flash answer, it’s a good idea. Another way could be changing the method in controller. For example if you have a store method in ExampleController that saves/process the form, comment the lines inside the method like this:

public function store(Request $request)
{
    /*
    $request->validate([
        'name' => 'required',
        'display' => 'required',
    ]);

    $category = new Category();
    $category->parent_id = $request->parent_id;
    $category->name = $request->name;
    $category->display = $request->display;
    $category->save();

     return redirect()->route('category.add');
    */
}

0👍

  • Create a dummy user in your database and have a middleware in place(if you did not have it before).

  • Save the demo user ID in a config file, let’s say config/app.php.

  • When someone visits your demo site, ask them to login and provide them the demo user credentials.

  • Create a session after the login(which you would anyway) with that user and whenever a post or any request that would affect the database is made, check like below-

Middleware Code:

if(Auth::user()->id === config('app.dummy_user_id'){
    if($request->getMethod() === 'GET' || $request->getMethod() === 'OPTIONS'){
       // for OPTIONS, you would play with the headers which I leave to you to edit
       return $next($request); 
    }else{
       return redirect()->back();
    }
}
// your further processing
return $next($request);

Leave a comment