为什么争论太少?我错过了什么?
Why too few arguments? What am I missing?
我正在做一个简单的表单来将数据发送到数据库,当我提交它时出现标题错误。
我不明白为什么会出现这个错误,我之前创建了很多表格,这是第一次出现问我 2 个参数,:S
Too few arguments to function Illuminate\Routing\PendingResourceRegistration::name(), 1 passed in C:\laragon\www\envio-curriculum\routes\web.php on line 18 and exactly 2 expected
web.php
<?php
Route::resource('/', 'enviarCurriculum\EnviarCurriculumController')->only(['index', 'create', 'store'])->name('**EnviarCurriculum**');
Expected 2 arguments. Found 1.intelephense(1005)
EnviarCurriculumController.php
<?php
namespace App\Http\Controllers\enviarCurriculum;
use App\EnviarCurriculum;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use app\Http\Requests\StoreEnviarCurriculumPost;
class EnviarCurriculumController extends Controller
{
public function index()
{
return view ('enviar_curriculum');
}
public function create()
{
return view ('enviar_curriculum', ['post' => new EnviarCurriculum()]);
}
public function store(StoreEnviarCurriculumPost $request)
{
EnviarCurriculum::create($request->validated());
return back() -> with('status', '¡Post creado con éxito!');
}
}
enviar_curriculum.blade.php
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="{{ route("EnviarCurriculum.store") }}" method="POST">
@csrf
<h4>Datos Personales</h4>
<small class="pull-right">sin espacios, ni guiones</small>
<br>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoNIF" class="form-control" placeholder="* NIF/NIE/Pasaporte" maxlength="20" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="nope" type="text" id="frmInscripcionEmpleoNombre" class="form-control" placeholder="* Nombre" maxlength="50" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoApellido1" class="form-control" placeholder="* 1º Apellido" maxlength="50" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoApellido2" class="form-control" placeholder="2º Apellido" maxlength="50" data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<select class="form-control" name="frmInscripcionEmpleoSexo" required id="frmInscripcionEmpleoSexo">
<option disabled selected value="">* Sexo</option>
<option value="H">Hombre</option>
<option value="M">Mujer</option>
</select>
<input type="submit" class="btn btn-primary" value="Enviar">
</form>
</body>
</html>
EnviarCurriculum.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class EnviarCurriculum extends Model
{
protected $fillable = ['nif', 'nombre', 'apellido1', 'apellido2', 'sexo'];
}
使用 Route::resource
,Laravel 需要 2 个参数而不是 1 个。
Route::resource('/', 'enviarCurriculum\EnviarCurriculumController')->only(['index', 'create', 'store'])->name('*','EnviarCurriculum');
发生这种情况的原因是因为您不能像您那样为资源路由命名。要更改默认资源路由名称,您可以这样做:
Route::resource('route-name', 'enviarCurriculum\EnviarCurriculumController')->names([
'index' => 'custom-name.index',
'store' => 'custom-name.store',
'create' => 'custom-name.create',
])->only(['index', 'create', 'store']);
来源:https://laravel.com/docs/8.x/controllers#restful-naming-resource-routes
我正在做一个简单的表单来将数据发送到数据库,当我提交它时出现标题错误。
我不明白为什么会出现这个错误,我之前创建了很多表格,这是第一次出现问我 2 个参数,:S
Too few arguments to function Illuminate\Routing\PendingResourceRegistration::name(), 1 passed in C:\laragon\www\envio-curriculum\routes\web.php on line 18 and exactly 2 expected
web.php
<?php
Route::resource('/', 'enviarCurriculum\EnviarCurriculumController')->only(['index', 'create', 'store'])->name('**EnviarCurriculum**');
Expected 2 arguments. Found 1.intelephense(1005)
EnviarCurriculumController.php
<?php
namespace App\Http\Controllers\enviarCurriculum;
use App\EnviarCurriculum;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use app\Http\Requests\StoreEnviarCurriculumPost;
class EnviarCurriculumController extends Controller
{
public function index()
{
return view ('enviar_curriculum');
}
public function create()
{
return view ('enviar_curriculum', ['post' => new EnviarCurriculum()]);
}
public function store(StoreEnviarCurriculumPost $request)
{
EnviarCurriculum::create($request->validated());
return back() -> with('status', '¡Post creado con éxito!');
}
}
enviar_curriculum.blade.php
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="{{ route("EnviarCurriculum.store") }}" method="POST">
@csrf
<h4>Datos Personales</h4>
<small class="pull-right">sin espacios, ni guiones</small>
<br>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoNIF" class="form-control" placeholder="* NIF/NIE/Pasaporte" maxlength="20" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="nope" type="text" id="frmInscripcionEmpleoNombre" class="form-control" placeholder="* Nombre" maxlength="50" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoApellido1" class="form-control" placeholder="* 1º Apellido" maxlength="50" required data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<input autocomplete="off" type="text" id="frmInscripcionEmpleoApellido2" class="form-control" placeholder="2º Apellido" maxlength="50" data-error="Por favor rellene este campo">
<div class="help-block with-errors"></div>
<select class="form-control" name="frmInscripcionEmpleoSexo" required id="frmInscripcionEmpleoSexo">
<option disabled selected value="">* Sexo</option>
<option value="H">Hombre</option>
<option value="M">Mujer</option>
</select>
<input type="submit" class="btn btn-primary" value="Enviar">
</form>
</body>
</html>
EnviarCurriculum.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class EnviarCurriculum extends Model
{
protected $fillable = ['nif', 'nombre', 'apellido1', 'apellido2', 'sexo'];
}
使用 Route::resource
,Laravel 需要 2 个参数而不是 1 个。
Route::resource('/', 'enviarCurriculum\EnviarCurriculumController')->only(['index', 'create', 'store'])->name('*','EnviarCurriculum');
发生这种情况的原因是因为您不能像您那样为资源路由命名。要更改默认资源路由名称,您可以这样做:
Route::resource('route-name', 'enviarCurriculum\EnviarCurriculumController')->names([
'index' => 'custom-name.index',
'store' => 'custom-name.store',
'create' => 'custom-name.create',
])->only(['index', 'create', 'store']);
来源:https://laravel.com/docs/8.x/controllers#restful-naming-resource-routes