skip to Main Content

my link to edit

<a href="/dashboard/rejected/{{ $reject->id }}/edit" class="badge bg-danger">{{ $reject->status }}</a>

my route

Route::resource('/dashboard/rejected', RejectController::class);

my controller

public function edit(Reject $reject)
{
    dd($reject);
    return view('dashboard.reject.edit',[
        'tittle' => 'Reject Stock',
        'reject' => $reject
    ]);
}

$reject on my controller is dont have data,
in my route list

GET|HEAD dashboard/rejected/{rejected}/edit rejected.edit›RejectController@edit

2

Answers


  1. I advise you to use the function route() to refer to your path instead of hard typing it.
    you can do:

    <a href="route('dashboard.reject.edit', $reject->id)" class="badge bg-danger">{{ $reject->status }}</a>
    

    then you should change the invoked function argument to be

    public function edit(string $reject_id)
    {
        dd($reject_id);
        return view('dashboard.reject.edit',[
            'tittle' => 'Reject Stock',
            'reject' => Reject::find($reject_id)
        ]);
    }
    

    finaly, your route name should be as following:

    Route::resource('dashboard.rejected', RejectController::class);
    

    this is a more ‘elegent’ way to code, hope you find this useful.

    Login or Signup to reply.
  2. When you use slash in resource , it will also be in route binding, so you should’n use it in resource , you can use dashboard-rejected in route and
    $dashboard_rejected as param in controller , and you will get data.

    on a note :
    put the noun in the plural in the route and the singular in the parameter,

    example:

    /user-posts , $userPost
    
    /posts , $post
    

    You also can customize route binding.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search