Laravel 9 "Missing required parameter for [Route:"

Viewed 100

I'm using Laravel 9 and trying to use CRUD with my model Project which has the following DB table.

table projects

When I try to edit a project using the button "edit" on this view: "projets.index":

@extends('header')
@section('content')
<div class="col-sm-8" style="background: rgba(204, 204, 204,0.5);padding:5%;width:100%">
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2 style="text-align: center">Les projets</h2>
            </div>
            <div class="pull-right">
                <a class="btn btn-success" href="{{ route('projets.create') }}"> Créée un nouveau projet</a>
            </div>
        </div>
    </div>
    @if ($message = Session::get('success'))
        <div class="alert alert-success">
            <p>{{ $message }}</p>
        </div>
    @endif
    <table class="table table-bordered">
        <tr>
            <th>id du projet</th>
            <th>description</th>
            <th width="280px">Action</th>
        </tr>
        @foreach ($projects as $project)
        <tr>
            <td>{{ $project->id_project }}</td>
            <td>{{ $project->description }}</td>
            <td>
                <form action="{{ route('projets.destroy',$project->id_project) }}" method="Post">
                    <a class="btn btn-primary" href="{{ route('galleries.index',$project->id_project,'id_project') }}">ajouter</a>
                    <a class="btn btn-primary" href="{{ route('projets.edit',[$project->id_project]) }}">Edit</a>
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="btn btn-danger">Delete</button>
                </form>
            </td>
        </tr>
        @endforeach
    </table>
    {!! $projects->links() !!}
</div>
@endsection

I have the following error:

"Missing required parameter for [Route: projets.update] [URI: projets/{projet}] [Missing parameter: projet]."

"projets.edit":

@extends('header')
@section('content')
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2>Edit projet</h2>
            </div>
            <div class="pull-right">
                <a class="btn btn-primary" href="{{ route('projets.index') }}"> Back</a>
            </div>
        </div>
    </div>
    @if ($errors->any())
        <div class="alert alert-danger">
            <strong>Whoops!</strong> There were some problems with your input.<br><br>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    <form action="{{ route('projets.update',$project->id_project) }}" method="POST" enctype="multipart/form-data">
        @csrf
        @method('PUT')
         <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>Company Address:</strong>
                    <input type="text" name="address" value="{{ $project->description }}" class="form-control" placeholder="Company Address">
                    @error('address')
                     <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                    @enderror
                </div>
            </div>
              <button type="submit" class="btn btn-primary ml-3">Submit</button>    
        </div>
    </form>
@endsection

Update function inside the controller (ProjectController):

public function update(Request $request, $id_project)
{
    $request->validate([ 
        'description' => 'required',
    ]);
    
    User::create($request->all());
    $project->description = $request->description;
    $project->save();
    
    return redirect()->route('projets.index')
                    ->with('success','project Has Been updated successfully');
}

public function edit(Project $project)
{
    return view('projets.edit',compact('project'));
}

Project model

<?php

namespace App\Models; 

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class Project extends Model

{

    protected $fillable = [

        'id_project', 'description'

    ];

}

Sorry if my questions seems strange English is not my first language

0 Answers
Related