Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jose-antonio-7's avatar

Problem Missing required parameter for [Route: ordenes.update] [URI: ordenes/{ordene}] [Missing parameter: ordene].

Hi, im getting this error, im making a laravel project where i have users, roles and orders, users and roles work just fine, i can create orders, but when i press the edit button i get this error

any idea what could be causing this problem?

here is my code, if anything is missing ill add it, im new to laravel sorry

OrdenController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Str;


use App\Models\Order;

class OrdenController extends Controller
{
    function __construct()
    {
        $this->middleware('permission:ver-orden | crear-orden | editar-orden | borrar-orden', ['only' =>['index']]);
        $this->middleware('permission:crear-orden', ['only' =>['create','store']]);
        $this->middleware('permission:editar-orden', ['only' =>['edit','update']]);
        $this->middleware('permission:borrar-orden', ['only' =>['destroy']]);


    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $ordenes = Order::paginate(5);
        return view('ordenes.index',compact('ordenes'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('ordenes.crear');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'status' => 'required',
            'direccion' => 'required',
            'notas' => 'required',
            'photo' => 'required',
        ]);
    
        $customerNumber = Str::random(10);
        while (Order::where('customer_number', $customerNumber)->exists()) {
            $customerNumber = Str::random(10);
        }
    
        $validatedData = $request->all();
        $validatedData['customer_number'] = $customerNumber;
    
        Order::create($validatedData);
    
        return redirect()->route('ordenes.index');
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Order $order)
    {
        return view('ordenes.editar',compact('order'));
        //Aqui ordenes podria ser orden, en el video venia blog en singular

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Order $order)
    {
        request()->validate([
            'status' => 'required',
            'direccion' => 'required',
            'notas' => 'required',
            'photo' => 'required',
            //Customer number no porque eso es automatico
        ]);

        $order->update($request->all());
    
        return redirect()->route('ordenes.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Order $order)
    {
        $order->delete();
    
        return redirect()->route('ordenes.index');
    }
}

Orden model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    use HasFactory;
    protected $fillable = ['status','direccion','notas','photo','customer_number'];
}

Orden migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB; //X, creacion de numero cliente

use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->string('status');
            $table->string('direccion');
            $table->string('notas');
            $table->string('photo');

            $table->string('customer_number')->unique();//X, creacion de numero cliente

            $table->timestamps();
        });

        //X, creacion de numero cliente
        $orders = DB::table('orders')->get();
        foreach ($orders as $order) {
            $customerNumber = $this->generateUniqueCustomerNumber();
            DB::table('orders')
                ->where('id', $order->id)
                ->update(['customer_number' => $customerNumber]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }

    //X, creacion de numero cliente
    private function generateUniqueCustomerNumber()
    {
        $customerNumber = mt_rand(1000000000, 9999999999);
        while (DB::table('orders')->where('customer_number', $customerNumber)->exists()) {
            $customerNumber = mt_rand(1000000000, 9999999999);
        }
        return $customerNumber;
    }
};

Orden edit view

@extends('layouts.app')

@section('content')
    <section class="section">
        <div class="section-header">
            <h3 class="page__heading">Editar Orden</h3>
        </div>
        <div class="section-body">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">                            
                   
                        @if ($errors->any())                                                
                            <div class="alert alert-dark alert-dismissible fade show" role="alert">
                            <strong>¡Revise los campos!</strong>                        
                                @foreach ($errors->all() as $error)                                    
                                    <span class="badge badge-danger">{{ $error }}</span>
                                @endforeach                        
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            </div>
                        @endif


                    <!-- <form action="{{ route('ordenes.update', ['ordene' => $order->id]) }}" method="POST"> -->
                    <form action="{{ route('ordenes.update',$order->id) }}" method="POST">
                        @csrf
                        @method('PUT')
                        <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <div class="form-group">
                                   <label for="status">status</label>
                                   <input type="text" name="status" class="form-control" value="{{ $order->status }}">
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <div class="form-group">
                                   <label for="direccion">direccion</label>
                                   <input type="text" name="direccion" class="form-control" value="{{ $order->direccion }}">
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-12 col-md-12">
                                <div class="form-group">
                                   <label for="photo">photo</label>
                                   <input type="text" name="photo" class="form-control" value="{{ $order->photo }}">
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-12 col-md-12">
                                                    
                                <div class="form-floating">
                                    <label for="notas">notas</label>
                                    <textarea class="form-control" name="notas" style="height: 100px">{{ $order->notas }}</textarea>                                
                                </div>
                            <br>
                            <button type="submit" class="btn btn-primary">Guardar</button>                            
                        </div>
                    </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

Orden index view

@extends('layouts.app')

@section('content')
    <section class="section">
        <div class="section-header">
            <h3 class="page__heading">Ordenes</h3>
        </div>
        <div class="section-body">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                
            
                        @can('crear-orden')
                        <a class="btn btn-warning" href="{{ route('ordenes.create') }}">Nuevo</a>
                        @endcan
            
                        <table class="table table-striped mt-2">
                                <thead style="background-color:#6777ef">                                     
                                    <th style="display: none;">ID</th>
                                    <th style="color:#fff;">status</th>
                                    <th style="color:#fff;">direccion</th>                                    
                                    <th style="color:#fff;">notas</th>
                                    <th style="color:#fff;">photo</th>   
                                    <th style="color:#fff;">customer_number</th>
                                    <th style="color:#fff;">created_at</th>                                                                      
                                                                      
                              </thead>
                              <tbody>
                            @foreach ($ordenes as $order)
                            <tr>
                                <td style="display: none;">{{ $order->id }}</td>                                
                                <td>{{ $order->status }}</td>
                                <td>{{ $order->direccion }}</td>
                                <td>{{ $order->notas }}</td>
                                <td>{{ $order->photo }}</td>
                                <td>{{ $order->customer_number }}</td>
                                <td>{{ $order->created_at }}</td>

                                <td>
                                    <form action="{{ route('ordenes.destroy',$order->id) }}" method="POST">                                        
                                        @can('editar-orden')
                                        <a class="btn btn-info" href="{{ route('ordenes.edit',$order->id) }}">Editar</a>
                                        @endcan

                                        @csrf
                                        @method('DELETE')
                                        @can('borrar-orden')
                                        <button type="submit" class="btn btn-danger">Borrar</button>
                                        @endcan
                                    </form>
                                </td>
                            </tr>
                            @endforeach
                            </tbody>
                        </table>

                        <!-- Ubicamos la paginacion a la derecha -->
                        <div class="pagination justify-content-end">
                            {!! $ordenes->links() !!}
                        </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
0 likes
3 replies
webrobert's avatar
Level 51

You route is using ordene but the method is using an order. They need to match

1 like
jose-antonio-7's avatar

@webrobert how can i do it? my routes are:

Route::group(['middleware' => ['auth']], function(){
    Route::resource('roles',RolController::class);
    Route::resource('usuarios',UsuarioController::class);
    Route::resource('ordenes',OrdenController::class);
});

i tried:

Route::put('/ordenes/{ordene}', 'OrderController@update')->name('ordenes.update');

but it didnt work

jose-antonio-7's avatar

thank you a lot, i overwrote the route with:

    Route::resource('ordenes',OrdenController::class)->parameters(['ordenes' => 'order']);

turns out that now the changes on the edit and the delete doesnt deletes but ey, its progress, again thanks

Please or to participate in this conversation.