// 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
}
May 10, 2019
10
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?
Please or to participate in this conversation.