Home > Blockchain >  Laravel Error: missing required parameter
Laravel Error: missing required parameter

Time:11-24

When I want to edit the post, I get Missing Required Parameter error, How can I fix that?

Missing required parameter for [Route: cms.edit] [URI: cms/{cm}/edit] [Missing parameter: cm]. (View: C:\xampp\htdocs\mycmsL\resources\views\cms\edit.blade.php)

This is articlesController:

public function edit(Article $article)
    {
        return view('cms.edit')
        ->with('article',$article)
        ->with('categories',Category::all())
        ->with('tags',Tag::all());
    }

And edit.blade.php:

<form method="POST" action="{{ route('cms.edit',['id'=> $article->id]) }}"  enctype="multipart/form-data">
@csrf 
@method('put')

<div class="mb-3">
  <input type="text" name="title" class="form-control" id="title" value="$article->title">
</div>
<div class="mb-3">
  <textarea  type="text" class="form-control" id="description" name="description" rows="5" value="$article->description"></textarea>
</div>
<div class="mb-3">
  <input type="file" class="form-control" name="image" id="image" value="$article->image">
</div>
<div class="mb-3">
  <textarea type="text" name="content" class="form-control" id="content" rows="15"  value="$article->content"></textarea>
</div>
<div class="mb-3">
  <select class="form-select" name="tag" aria-label="Default select example">

      @foreach ($tags as $tag) ?>
        <option value="{{$tag->id}}"> {{$tag->name}} </option>
      @endforeach
  </select>
</div>
  <div hljs-number">3">
    <select hljs-string">" name="category" aria-label="Default select example">
      @foreach ($categories as $category) ?>
        <option value="{{$category->id}}"> {{$category->name}} </option>
      @endforeach
    </select>
  </div>
  
<button hljs-string">">Submit</button>
</form>

This is my route:

  Route::resource('cms',articlesController::class);

and {{dd($article->id)}} returning me null when I want to see data .

CodePudding user response:

You should use same param url name in the function also

//Change this from 
{{ route('cms.edit',['id'=> $article->id]) }}
//TO
{{ route('cms.edit',['cm'=> $article->id]) }}

public function edit(Article $cm) // old param name '$article' 
    {
        return view('cms.edit')
        ->with('article',$cm)
        ->with('categories',Category::all())
        ->with('tags',Tag::all());
    }



CodePudding user response:

i changed this part route('cms.edit',['cms'=> $article->id]) But the error was not fixed

this is the route list: enter image description here

  • Related