我正在尝试将 json 存储到数据库中并将其加载回来
我尝试存储
{name: "John", age: 31, city: "New York"}
Run Code Online (Sandbox Code Playgroud)
它存储正确。我检查了数据库,它显示正确。
{姓名:“约翰”,年龄:31,城市:“纽约”}
我不断地看到风景
"{name: \"John\", age: 31, city: \"New York\"}"
Run Code Online (Sandbox Code Playgroud)
这是我的代码。
public function store()
{
$paste = new Paste;
$paste->uuid = Str::uuid()->toString();
$paste->data = trim(Request::get('data',''));
$paste->save();
return Redirect::to('/paste/'.$paste->uuid)->with('success', 'Created');
}
public function show($uuid)
{
$paste = Paste::where('uuid',$uuid)->first();
return response()->json($paste->data);
}
Run Code Online (Sandbox Code Playgroud)
对我有什么提示吗?
可在此处重现
https://www.bunlongheng.com/paste
如果我这样做
public function show($uuid)
{
$paste = Paste::where('uuid',$uuid)->first();
return View::make('layouts.fe.pastes.show', get_defined_vars());
}
Run Code Online (Sandbox Code Playgroud)
在我看来,我只有这 1 行
{!!$paste->data!!}
Run Code Online (Sandbox Code Playgroud)
我得到的数据与我现在提交的数据相同。
{name: "John", age: 31, city: "New York"}
Run Code Online (Sandbox Code Playgroud)
但浏览器将其检测为文本,而不是响应 …
我有一个控制器,其中包含三个功能(注册、登录、忘记密码)。对于登录和注册,它工作正常,但是当我尝试在邮递员中使用 API 时,我收到错误,之前我使用单独的控制器来执行忘记密码()功能当时它工作正常,现在我将该控制器移至 USerController 我得到 500 个内部服务器,请帮我解决这个问题..
UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Models\User;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use App\Models\PasswordReset;
use App\Notifications\ResetPasswordNotification;
class UserController extends Controller
{
public function __construct() {
$this->middleware('auth:api', ['except' => ['login', 'register']]);
}
public function register(Request $request)
{
$this->validate($request, [
'fullName'=>'required|string|between:3,15',
'email'=>'required|email|unique:users',
'password'=>'required|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$/',
'mobile'=>'required|digits:10'
]);
$user = new User([
'fullName'=> $request->input('fullName'),
'email'=> $request->input('email'),
'password'=> bcrypt($request->input('password')),
'mobile'=>$request->input('mobile')
]);
$user->save();
// User::create($request->getAttributes())->sendEmailVericationNotification();
return response()->json(['message'=>'Successfully Created user'],201);
}
public function login(Request $request)
{
$this->validate($request, [
'email' …Run Code Online (Sandbox Code Playgroud) 这是我的目录结构。
-resources
-css
-mycss.css
-js
-myjs.js
-myimagesfolder
-views
-admin
-home.blade.php
Run Code Online (Sandbox Code Playgroud)
我如何访问resources>css>mycss.css、resources>js>myjs.js和resources>mymagesfolder>images in my views>admin>home.blade.php。
我已将 Laravel 8 应用程序升级到版本 9,根据文档:升级指南,该resources/lang目录现在位于根项目目录 ( lang) 中。
我已将该lang目录移至项目的根目录,但似乎不起作用。
// config/app.php
'locale' => 'pt-BR',
Run Code Online (Sandbox Code Playgroud)
和
// lang/pt-BR/messages.php
return [
'welcome' => 'Welcome to the app!',
];
Run Code Online (Sandbox Code Playgroud)
控制器
return response()->json([
'message' => Lang::get('messages.welcome') // it returns "messages.welcome"
]);
Run Code Online (Sandbox Code Playgroud)
但是当我将lang目录更改回 时/resources/lang,它可以像以前的 laravel 版本一样正常工作。所以我创建了一个新的 Laravel 9 项目,它工作了,这让我认为需要一些额外的配置,但它没有记录在升级指南中。我的composer.json依赖项与新的 laravel 项目完全相同。Laravel 是否需要进行任何额外配置才能识别该目录?
在通过 composer 安装 jetstreamcomposer require laravel/jetstream
之后,突然得到一个 ErrorException ,说没有这样的文件或目录。
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
ErrorException
require(F:\laravelApps\test_proj\vendor\laravel\jetstream\src/../routes/.php): failed to open stream: No such file or directory
at F:\laravelApps\test_proj\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:144
140? */
141? protected function loadRoutesFrom($path)
142? {
143? if (! ($this->app instanceof CachesRoutes && $this->app->routesAreCached())) {
? 144? require $path;
145? }
146? }
147?
148? /**
1 F:\laravelApps\test_proj\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:144
require()
2 F:\laravelApps\test_proj\vendor\laravel\jetstream\src\JetstreamServiceProvider.php:172
Illuminate\Support\ServiceProvider::loadRoutesFrom("F:\laravelApps\test_proj\vendor\laravel\jetstream\src/../routes/.php")
Script @php artisan package:discover --ansi handling the post-autoload-dump event …Run Code Online (Sandbox Code Playgroud) 有谁知道为什么它会引发以下错误以及如何修复它?我还尝试使用npm install多次重新安装所有软件包。在 Windows 上重新安装 NodeJS 不起作用;我正在使用 Laravel 8.22.0。
完整日志
0 verbose cli [
0 verbose cli 'D:\\Programme\\NodeJS\\node.exe',
0 verbose cli 'D:\\Programme\\NodeJS\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli 'run',
0 verbose cli 'development'
0 verbose cli ]
1 info using npm@7.3.0
2 info using node@v15.5.1
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:D:\Programme\NodeJS\node_modules\npm\npmrc Completed in 2ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:D:\My\Path\.npmrc 33,,,,,,,,Completed in 0ms
9 …Run Code Online (Sandbox Code Playgroud) 使用带有斜杠的 API 时出现问题。
路线
Route::post('user/register','UserController@register');
Run Code Online (Sandbox Code Playgroud)
当我POST从邮递员/网站调用此路由时,它工作正常,但我从移动设备调用了此路由,并带有如下斜杠。
user/register/
Run Code Online (Sandbox Code Playgroud)
默认情况下,Laravel 删除尾部斜杠,但GET在我转储请求方法时发出请求。
$method = $_SERVER['REQUEST_METHOD'];
$json = json_encode(['response' => $method], true);
result -> "{response : 'GET'}"
Run Code Online (Sandbox Code Playgroud)
而且我无法获取请求正文。
注意:我尝试了很多解决方案,但找不到任何解决方案,而且我无法从移动端删除或更新路由调用,因此我必须在服务器端处理它。
如何在Laravel 8中设置每秒速率限制器。我需要设置每秒而不是每分钟的速率限制器。
速率限制器 (Laravel 8) - https://laravel.com/docs/8.x/routing#rate-limiting
现在我可以使用 Laravel 的速率限制器几分钟、几小时等。但我正在尝试实现一秒钟的速率限制器。我想限制每秒 25 个请求。(从“Illuminate\Cache\RateLimiting\Limit”导出的 Limit 类)
请检查我使用过的以下代码
RateLimiter::for('api', function (Request $request) {
return [
// Rate limiter based on Client IP Address
Limit::perMinute(env('IP_ADDR_RATE_LIMITER_PER_MINUTE', 60))->by($request->ip())->response(function () {
....
}),
// Rate limiter based on API key/User
Limit::perMinute(env('API_KEY_RATE_LIMITER_PER_MINUTE', 60))->by($request->input('key'))->response(function () {
...
})
];
});
Run Code Online (Sandbox Code Playgroud)
有没有办法限制每秒 25 个请求?
注意:还尝试在 Illuminate\Cache\RateLimiting\Limit 中添加/更改函数,其中我尝试更改每分钟函数。提前致谢。
我开始使用 Laravel 8 构建一个 Web 应用程序。我注意到 Laravel 8 中的很多事情都发生了变化,包括身份验证。现在,我正在尝试使用 Jetstream 进行身份验证。
我已运行以下命令将其集成到应用程序中。
composer require laravel/jetstream
php artisan jetstream:install inertia
npm install && npm run dev
Run Code Online (Sandbox Code Playgroud)
当我去/register路线时,我可以看到包含姓名、电子邮件、密码和密码确认字段的注册表。我想要做的是我想添加另一个名为“公司”的字段,我想对其应用自定义验证规则。
我在 Jetstream 文档中发现,我可以在 JetstreamServiceProvider 类的引导方法中自定义身份验证过程,如下所示。
Fortify::authenticateUsing(function (Request $request) {
});
Run Code Online (Sandbox Code Playgroud)
但不适用于注册。如何自定义注册过程添加新字段和应用自定义验证规则?
我已经在我的 Linux Mint 20 上安装了 Laravel 8 进行个人实验,所以我对 Laravel 的新版本很陌生。我搜索了许多来源如何使用 CRUD 方法显示表,以便该表显示在网络中,其中包含来自 MySQL 数据库的数据
但是当我尝试用 CRUD 方法显示表时,它看起来像这样:
Illuminate\Database\QueryException 找不到驱动程序(SQL:select * from
list)
在本地主机:8000/home/tabel
我尝试通过修复 .env 文件、控制器文件、blade 文件和 web.php 来解决此问题,使其正确,但仍然错误。
这是我的配置文件,我对其进行了如下更改:
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=people
DB_USERNAME=root
DB_PASSWORD=
Run Code Online (Sandbox Code Playgroud)
homeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class homeController extends Controller
{
public function home()
{
return "home";
}
public function tabel()
{
$tabelku = DB::table('list')->get();
return view('tabel', ['people' => $tabelku]);
}
}
Run Code Online (Sandbox Code Playgroud)
tabel.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
</head>
<body> …Run Code Online (Sandbox Code Playgroud)