Delano van londen
Delano van londen

Reputation: 416

Laravel route not defined but it is defined

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 class="btn btn-big btn-succes" style="background: orange;" href="{{ route('partner.file.show', $file->id) }}">View</a>
                        </td>
                        <td>
                            <a class="btn btn-big btn-succes" 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>

Upvotes: 0

Views: 796

Answers (2)

Ebi
Ebi

Reputation: 384

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');

Upvotes: 4

xenooooo
xenooooo

Reputation: 1216

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

Upvotes: 0

Related Questions