I am trying to retrieve both event data and student data on the dashboard view but they seem to be conflicting with each other. The student records is also showing at where my Event records is supposed to be displayed.
This is how it looks like:
Routes
Route::post('/dashboard/submit', 'EventController@submit');
Route::get('/dashboard', 'EventController@getevent');
Route::post('/dashboard/student/pay', 'PaymentController@submit');
Route::post('register','StudentRegister@register');
Route::get('/dashboard', 'StudentRegister@getStudents');
EventController.php
class EventController extends Controller
{
public function submit(Request $request)
{
$message = new Event;
$message->title = $request->input('title');
$message->deadline = $request->input('deadline');
$message->message = $request->input('message');
$message->save();
return redirect('/dashboard')->with('status', 'Event Added');
}
public function getevent()
{
$msgevent = Event::orderBy('id', 'DESC')->get();
return view('dashboard')->with('dashboard', $msgevent);
}
}
studentRegister.php
public function getStudents(){
$Students = Student::all();
return view('dashboard') -> with('dashboard', $Students);
}
I have These in my dashboard.blade.php
<div class="paginate-no-scroll 5">
<div class="items">
@if(count($dashboard) > 0)
@foreach ($dashboard as $msg)
<div>
<svg class="bd-placeholder-img mr-2 rounded" width="24" height="24" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: 32x32">
<rect width="30%" height="30%" fill="#007bff"/>
<text x="50%" y="50%" fill="#007bff" dy=".3em"></text>
</svg>
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">{{$msg -> title}}</strong> | {{$msg -> deadline}} |<b
style="color: #25027f"> @username</b> | <a href="#" style="text-decoration: underline;">Edit</a> |
<a href="/delete/{!! $msg -> id !!}" style="text-decoration: underline;">Delete</a><br>
{{$msg -> message}}
</div>
@endforeach
@endif
<table id="tableData" class="table table-bordered table-striped">
<thead>
<th>#</th>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</thead>
@if(count($dashboard) > 0)
@foreach ($dashboard as $std)
<tr>
<td style="text-align:center"><img src="uploads/{{$std->image}}" style="width: 50px;height: 50px; border-radius: 50%" alt="{{$std->image}}"></td>
<td style="text-align:center; padding-top: 25px;">{{$std->studentID}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->fName}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->surName}}</td>
<td style="text-align:center; padding-top: 25px;"><a href="" class="btn btn-primary"> view</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
Why you call two events with same name. You change your code like below.
studentRegister.php
public function getStudents(){
$students = Student::all();
$msgevents = Event::all()->orderBy('id', 'DESC');
return view('dashboard', [
'students' => $students,
'msgevents' => $msgevents
]);
}
Don't forgot to add use App\Event;
in the file.
dashboard.blade.php
<div class="paginate-no-scroll 5">
<div class="items">
@if(count($msgevents) > 0)
@foreach ($msgevents as $msg)
<div>
<svg class="bd-placeholder-img mr-2 rounded" width="24" height="24" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" aria-label="Placeholder: 32x32"><rect width="30%" height="30%" fill="#007bff"/><text x="50%" y="50%" fill="#007bff" dy=".3em"></text></svg>
<p class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<strong class="d-block text-gray-dark">{{$msg -> title}}</strong> | {{$msg -> deadline}} |<b style="color: #25027f"> @username</b> | <a href="#" style="text-decoration: underline;">Edit</a> | <a href="/delete/{!! $msg -> id !!}" style="text-decoration: underline;">Delete</a><br>
{{$msg -> message}}
</div>
@endforeach
@endif
<table id="tableData" class="table table-bordered table-striped">
<thead>
<th>#</th>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</thead>
@if(count($students) > 0)
@foreach ($students as $std)
<tr>
<td style="text-align:center"><img src="uploads/{{$std->image}}" style="width: 50px;height: 50px; border-radius: 50%" alt="{{$std->image}}"></td>
<td style="text-align:center; padding-top: 25px;" >{{$std->studentID}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->fName}}</td>
<td style="text-align:center; padding-top: 25px;">{{$std->surName}}</td>
<td style="text-align:center; padding-top: 25px;"><a href="" class="btn btn-primary"> view</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>