Home > Software design >  Laravel route not defined but it is defined
Laravel route not defined but it is defined

Time:10-21

Route [partner.file.download] not defined. is the error i get, but this route is defined. and yes i am logged in as a 'partner'

Web.php

Route::group(['middleware' => 'role:partner', 'prefix' => 'partner', 'as' => 'partner.'], function(){

    Route::resource('/dashboard', App\Http\Controllers\partner\PartnerController::class);
   Route::resource('/profile', App\Http\Controllers\partner\ProfileController::class);
   Route::resource('/file', App\Http\Controllers\partner\FileController::class);
});

controller

  public function show($id)
    {
        $file = File::findOrFail($id);

        return view('partner.file.viewfile', compact('file'));
    }
    
    public function download($id)
    {
        return view('partner.file.index', compact('file));
    }

index.blade

  <tbody>
                    @foreach($files as $file)
                    <tr>
                        <td>{{$file->title}} </td>
                        <td>
                            <a  style="background: orange;" href="{{ route('partner.file.show', $file->id) }}">View</a>
                        </td>
                        <td>
                            <a  style="background: green;" href="{{ route('partner.file.download', $file->id) }}"></a>
                        </td>
                        <td>{{@$file->language->name}} </td>
                        @foreach($file->tag as $tags)
                        <td style="background:{{$tags['color']}} ;">{{@$tags->name}} </td>
                        @endforeach
                        
                    </tr>
                    @endforeach
                </tbody>

CodePudding user response:

PLEASE READ THE DOCS

as @aynber mentioned in the comments, when you create routes using resource(), it will create index, create, store, show, edit, update and delete. There is no "download" route here.

If you need a route that is not in the list of default routes (here you need download), you should create that one explicitly as below:

Route::group(['middleware' => 'role:partner', 'prefix' => 'partner', 'as' => 'partner.'], function(){

   Route::resource('/dashboard', App\Http\Controllers\partner\PartnerController::class);
   Route::resource('/profile', App\Http\Controllers\partner\ProfileController::class);
   Route::resource('/file', App\Http\Controllers\partner\FileController::class);
});


// HERE: you add the named route you need
Route::get(
    '/file/download',
    [App\Http\Controllers\partner\FileController::class, 'download']
)->name('file.download');

CodePudding user response:

When using Route::resource() the only accessible methods to the controller are index, create, store, show, edit, update and delete.

You can check this at the documentation

  • Related