单击Submit按钮后,我将存储json,但显示404未找到



我正在尝试使用以下教程中提交的数据制作json文件https://www.tutsmake.com/laravel-8-create-json-file-download-from-text/但我面临着一些问题。帮帮我,兄弟。我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮我吧,兄弟,我正面临问题。帮帮我,兄弟这是jsonControler.php


namespace AppHttpControllers;
use Redirect,Response;
use IlluminateHttpRequest;
use AppModelsTest;
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));
}
}

这是wewb.php

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

这是表格功能

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

这是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>

我认为你在表单Action上的帖子url是错误的。。

您的URL应该是URL('json-file-download'(

最新更新