PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 15, 2022

[FIXED] Why too few arguments? What am I missing?

 November 15, 2022     laravel, laravel-6, php     No comments   

Issue

I'm doing a simple form to send data to DB and when I submit it it appears the title error.

I don't understand why this error is appearing, I created a lot of forms before and this is the first time it appears asking me 2 arguments, :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'];
}

Solution

The reason that this is happening is because you can't give a name to resource route like you did. In order to change default resource route names, you can do this:

Route::resource('route-name', 'enviarCurriculum\EnviarCurriculumController')->names([
            'index' => 'custom-name.index',
            'store' => 'custom-name.store',
            'create' => 'custom-name.create',
        ])->only(['index', 'create', 'store']);

Source: https://laravel.com/docs/8.x/controllers#restful-naming-resource-routes



Answered By - zlatan
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,207,242

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing