Msoft
201
10
Laravel

Not working show function in Laravel 5.7

Posted 1 month ago by Msoft

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','[email protected]')->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?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.