Tarenk 77
Tarenk 77

Reputation: 95

Laravel returns 404 error when passing a parameter

Hello when I send a data press a link to show another view laravel returns a 404 error, what am I failing?, I have created other crud and I have had no problems so far

Expansion -> index.blade.php:

<a href="{{url('/cards/'.$expansion->exp_id.'/vcards')}}"class="btn btn-primary form-control" >Go!</a>

URL:

http://localhost/CardSystem/cartas/1/vcards

Route:

Route::resource('cards', 'cardControllerr');

cardController:

 public function vcards($id){
    $data['cards']= DB::table('cards')
    ->join('expansion','expansion.exp_id','=','cards.exp_id')
    ->select('cards.card_id','cards.card_nom','expansion.exp_nom')
    ->where('cards.exp_id','=',$id)
    ->orderBy('cards.card_num')
    ->paginate(5);

    return view('cards.vcards',$data);

vcards.blade.php:

@extends('layouts.app')
@section('content')
<div class="container">
@foreach($cards as $card)
<div class="form-group">

     <h5 class="card-title">{{$card->card_nom}}</h5>

</div>
@endforeach

</div>
@endsection

Upvotes: 0

Views: 197

Answers (1)

mrhn
mrhn

Reputation: 18966

I think you misunderstood routing, views etc.

For your controller to be hit, you will need to make the following route.

Route::get('cartas/{card}/vcards', 'cardControllerr@vcards')->name('cartas.vcards');

If you wanna link to this route use route().

route('cartas.vcards', ['card' => $card]);

Upvotes: 1

Related Questions