Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Msoft's avatar
Level 1

Not working show function in Laravel 5.7

I have table studentcource and store students cource data using studentcourceController store function here

public function store(Request $request)
    {
        $studentcource = New Studentcource;
        $studentcource->name = $request->input('name');
        $studentcource->address = $request->input('address');
        $studentcource->telephone = $request->input('telephone');
        $studentcource->cource = $request->input('cource');
        $studentcource->save();
        return redirect()->route('studentcourcedata');
        
        
    }

data storing is working fine. but I need redirect to studentcourcedata.blade.php after storing the data. show function is here in same controller,

public function show($id)
    {
        $studentcources = Studentcource::find($id);
        return view('studentcourcedata')->WithStudentcources($studentcources);
    }

and studentcourcedata.blade.php is like this

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Student Cource Data</div>

                <div class="card-body">
                    <table class="table">
                    <thered>
                     <tr>
                         <td>Id</td>
                         <td>Name</td>
                         <td>Address</td>
                         <td>Telephone</td>
                         <td>Cource</td>
                     </tr>
                    </thead>

                    <tbody>
                      @foreach ($studentcources as $studentcource)
                      <tr>
                        <td>{{$studentcource->id}}</td>
                        <td>{{$studentcource->name}}</td>
                        <td>{{$studentcource->address}}</td>
                        <td>{{$studentcource->telephone}}</td>
                        <td>{{$studentcource->cource}}</td>
                        

                      </tr>

                      @endforeach
                    </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

and my route is

Route::get('studentcourcedata','StudentcourceController@show')->name('studentcourcedata');

but I got following error here

Too few arguments to function App\Http\Controllers\StudentcourceController::show(), 0 passed and exactly 1 expected

how can I fix this problem?

0 likes
10 replies
Sergiu17's avatar
// ERROR
Route::get('studentcourcedata','StudentcourceController@show')->name('studentcourcedata');

// FIX IT BY ADDING {ID} WILDCARD TO THE ROUTE
Route::get('studentcourcedata/{id}','StudentcourceController@show')->name('studentcourcedata');

// Because
class StudentcourceController extends Controller
{
    public function show($id) // <---------- this function waits a parameter 
}
Msoft's avatar
Level 1

@sergiu17 now got this error message Missing required parameters for [Route: studentcourcedata] [URI: studentcourcedata/{id}].

Vandan29's avatar

Controller file change those line

public function show($id)

    {
        $studentcources = Studentcource::find($id);
        return view('studentcourcedata',compact('studentcources'));
    }

and my route is

            Route::get('studentcourcedata/{id}','StudentcourceController@show')->name('studentcourcedata');

try this

Wobbie's avatar

If you have a link to "studentcourcedata" you have to pass the $id:

route('studentcourcedata', $id);
Msoft's avatar
Level 1

@vandan29 @wobbie @robstar please see my form to save data,

  <form action="{{url('studentcourceform')}}" method="post">

I think problem is here because see my error massage

Missing required parameters for [Route: studentcourcedata] [URI: studentcourcedata/{id}].

please see my store route

Route::post('studentcourceform','StudentcourceController@store');
Sergiu17's avatar

@MSOFT - This is other route, the problem is the link to show method

// this is in the for loop somewhere
<a href="{{ url('studentcourcedata', ['id' => $id]) }}">Student Course</a>
  1. Update de route as I said
Route::get('studentcourcedata/{id}','StudentcourceController@show')->name('studentcourcedata');
  1. Search in your project for {{ url('studentcourcedata') }}

  2. Update it, by passing the ID, {{ url('studentcourcedata', ['id' => $id]) }}

Vandan29's avatar

@msoft Try this store data

<form action="{{url('studentcourceform')}}" method="post">

Route::post('studentcourceform','StudentcourceController@store');

$studentcource = Studentcource::create([
            'name' => $request->name,
            'address' => $request->address,
        'telephone' => $request->telephone,
        'cource' => $request->cource
    ]);
Tray2's avatar

Like others have said you need the correct route for your show method.

Route::get('studentcourcedata/{id}','StudentcourceController@show')->name('studentcourcedata');

Then you need to update the redirect call in your store method to match the new route

return redirect()->route('studentcourcedata', ['id' => $studanetcource->id]);

Please or to participate in this conversation.