After clicking Submit button it takes me to store-json but showing 404 not found

Viewed 74

I am trying to make json file with submitted data following tutorial https://www.tutsmake.com/laravel-8-create-json-file-download-from-text/ but I am facing problems. help me bro. I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me bro I am facing problems. help me broI am facing problems. help me bro This is jsonControler.php


namespace App\Http\Controllers;
use Redirect,Response;
use Illuminate\Http\Request;
use App\Models\Test;

class JsonController extends Controller
{
   public function index()
   {
      return view('json_form');
   }

  public function download(Request $request)
  {
      $data = $request->only('name','email','mobile_number');
      $test['token'] = time();
      $test['data'] = json_encode($data);
      Test::insert($test);
      $fileName = $test['token']. '_datafile.json';
      File::put(public_path('/upload/json/'.$fileName),$test);
      return download(public_path('/upload/jsonfile/'.$fileName));
  }

}

this is wewb.php

Route::post('json-file-download', [JsonController::class, 'download']);
Route::get('/', function () {
    return view('json');
});

This is table function

public function up(){
        Schema::create('tests', function (Blueprint $table) {
            $table->increments('id');
            $table->string('token')->nullable();
            $table->text('data')->nullable();
            $table->timestamps();
        });
    }

This is json.blade.php

<!doctype html>
<html lang="en">
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <title>Laravel Store Data To Json Format In Database - Tutsmake.com</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
  <style>
   .error{ color:red; }
  </style>
</head>

<body>

<div class="container">
    <h2 style="margin-top: 10px;">Laravel Store Data To Json Format In Database - Tutsmake.com</h2>
    <br>
    <br>

    @if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
          <strong>{{ $message }}</strong>
    </div>
    <br>
    @endif

    <form id="laravel_json" method="post" action="{{url('store-json')}}">
      @csrf
      <div class="form-group">
        <label for="formGroupExampleInput">Name</label>
        <input type="text" name="name" class="form-control" id="formGroupExampleInput" placeholder="Please enter name">
      </div>
      <div class="form-group">
        <label for="email">Email Id</label>
        <input type="text" name="email" class="form-control" id="email" placeholder="Please enter email id">
      </div>
      <div class="form-group">
        <label for="mobile_number">Mobile Number</label>
        <input type="text" name="mobile_number" class="form-control" id="mobile_number" placeholder="Please enter mobile number">
      </div>
      <div class="form-group">
       <button type="submit" class="btn btn-success">Submit</button>
      </div>
    </form>

</div>

</body>
</html>
1 Answers

I think your post url on form Action is wrong..

Your URL should be url('json-file-download')

Related