how to pass data from my controller to the view in laravel 8 - laravel-8

am trying to retrieve data from the controller and send it through and email to student but it not working .i have tried it but it not going
public function test(){
$welcome = DB::table('results')
->select('studentinfos_id','marks','subject_code','name','email','rollid','classname','classnumber','image_path')
->join('studentinfos','studentinfos.id','=','results.studentinfos_id')
->join('subjects','subjects.id','=','results.subjects_id')
->join('addclasses','addclasses.id','=','results.addclasses_id')
->where('studentinfos.id',1)
->orderBy('subject_code','ASC')
->get();
Mail::to('serge#gmaile','divine')->cc('leade#gmail')->send(new mytestmail($welcome));
echo 'check ur inbox';
}
how do i get all the result from the $welcome in my view.blade.php
i was hopping that i will send and email that contains student info and result of there marks and subject through email
<div class="container">
<div class="text-center">
<h1> Result for {{ $classname }} student </h1>
</div>
<div class="border bg-white seespace p-3">
<div class="row">
<div class="col-md-8">
<table class="table table-borderless">
<tr>
<th>CLASS</th>
<td>{{ $welcome->classname }} {{ $welcome->classnumber }}</td>
</tr>
<tr>
<th>FULL NAME</th>
<td>: {{ $welcome->name }}</td>
</tr>
<tr>
<th>EMAIL</th>
<td>: {{ $welcome->email }}</td>
</tr>
<tr>
<th>ENROLLMENT</th>
<td>: {{ $welcome->enrollment }}</td>
</tr>
</table>
</div>
<div class="col-md-4">
<img class=" imgreport center" src="{{ asset('images/' . $welcome->image) }}"
alt="Card image cap">
</div>
</div>
<nav class="bg-dark text-white-50 mb-5">
<div class="container">
<div class="row p-3">
</div>
</div>
</nav>
<table class="table text-center table-bordered table-responsive py-3">
<thead class="thead-info text-center">
<tr>
<th>no</th>
<th>subject</th>
<th>marks</th>
</tr>
</thead>
<tbody>
<?php $num=1;
$total = 0;
$name;
?>
#foreach($welcome as $see)
<tr>
<td>{{ $num++ }}</td>
<td>{{ $see->subject_code }}</td>
<td>{{ $see->marks }}</td>
</tr>
<?php
$total += $see->marks ?>
#endforeach
<tr>
<td></td>
<td >total marks</td>
<td>{{ $total }}</td>
</tr>
<tr>
<td></td>
<td>Download</td>
<td>
<form action="/print" method="get">
<input type="hidden" value="{{$studnet}}" name='id' >
<button class="btn btn-info">Download</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
#stop

you have to pass the welcome variable to your view.
In the controller method add the data when displaying your view:
return view('view', ['welcome' => $welcome]);
https://laravel.com/docs/8.x/views#passing-data-to-views

Related

Showing table heading once in VueJS component

I have a search built in VueJS and the results of the search are displayed in a separate component. I want to display the data in a table with the table headings. The issue I'm having is that the table heading appears before each row. How do I get it to appear once? Im sure this is easy but I cant think how to do this. Im fairly new to Vue, so any help appreciated.
<table class="table table-hover" id="simpleTable">
<thead>
<tr>
<th
v-on:click="sortTable(title)"
:key="title"
scope="col"
class="col-md-3"
>
Course
</th>
<div
class="arcoursedata"
v-if="title == sorttitle"
v-bind:class="ascending ? 'arcoursedata_up' : 'arcoursedata_down'"
></div>
<th scope="col">Award</th>
<th scope="col">Level</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-3">
{{ title }}
</td>
<td>
{{ award }}
</td>
<td class="col-md-3">
{{ level }}
</td>
<td class="col-md-3">
<a
:href="result.displayUrl"
class="btn-sm btn-primary"
role="button"
>
<span class="sr-only">Read more about {{ title }}</span> Read
more</a
>
</td>
</tr>
</tbody>
</table>
You need to separate row from tbody to component. And do v-for only on this component and not on the entire table.
It will be look like:
<table class="table table-hover" id="simpleTable">
<thead>
<tr>
<th
v-on:click="sortTable(title)"
:key="title"
scope="col"
class="col-md-3"
>
Course
</th>
<div
class="arcoursedata"
v-if="title == sorttitle"
v-bind:class="ascending ? 'arcoursedata_up' : 'arcoursedata_down'"
></div>
<th scope="col">Award</th>
<th scope="col">Level</th>
</tr>
</thead>
<tbody>
<rowComponent v-for="rowData in tableData" :row="rowData"></rowComponent>
</tbody>
</table>
And RowComponent will look like:
<td class="col-md-3">
{{ row.title }}
</td>
<td>
{{ row.award }}
</td>
<td class="col-md-3">
{{ row.level }}
</td>
<td class="col-md-3">
<a :href="row.displayUrl"
class="btn-sm btn-primary"
role="button">
<span class="sr-only">Read more about {{ row.title }}</span> Read
more</a>
</td>
<script>
export default {
name: "rowComponent",
props: ['row']
}
</script>

Is Vue 3 backwards compatible with Vue 2?

In different posts around the internet (for example this one) I found that Vue 2 code should work with Vue 3 but for me it does not. For example I have simple component
<template>
<div class="overflow-x-auto bg-white rounded-lg shadow overflow-y-auto relative">
<table class="table">
<thead>
<tr class="text-left">
<th>
<label>
<input type="checkbox">
</label>
</th>
<th>User ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Gender</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
<input type="checkbox" name="1">
</label>
</td>
<td> <span>{{ id }}</span> </td>
<td> <span>Cort</span> </td>
<td> <span>Tosh</span> </td>
<td> <span>{{ email }}</span> </td>
<td> <span>Male</span> </td>
<td> <span>327-626-5542</span> </td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
data() {
return {
id: 1,
email: 'test#mail.com'
}
},
mounted() {
alert('mounted');
},
created() {
alert('created');
}
};
</script>
The table is generated just fine, but both mounted and created not fired when component made. Also the email and id not shown. Only the table is shown.
Your code works:
Vue.createApp({
data() {
return {
id: 1,
email: 'test#mail.com'
}
},
created() {
alert('created')
},
mounted() {
alert('mounted')
}
}).mount('#app')
<script src="https://unpkg.com/vue#next"></script>
<div id="app" class="overflow-x-auto bg-white rounded-lg shadow overflow-y-auto relative">
<table class="table">
<thead>
<tr class="text-left">
<th>
<label>
<input type="checkbox">
</label>
</th>
<th>User ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Gender</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label>
<input type="checkbox" name="1">
</label>
</td>
<td> <span>{{ id }}</span> </td>
<td> <span>Cort</span> </td>
<td> <span>Tosh</span> </td>
<td> <span>{{ email }}</span> </td>
<td> <span>Male</span> </td>
<td> <span>327-626-5542</span> </td>
</tr>
</tbody>
</table>
</div>

How To Make A Loop Using v-for With Condition "Like Forelse" In Laravel Framework

I'm Just Trying To Do Something using Vue Similar To forelse in laravel framework blade,
This Is Just To Do a Test To Confirm If Table Has Records Or Not, If No, It Allows Me To Add A Default Value Like :
<tr>
<td colspan="4">There's No Records Yet</td>
</tr>
I Tried This But It Gives Me [vue/no-use-v-if-with-v-for]
<tr v-for="(category, index) in this.categories" :key="index" v-if="categories">
<td>{{ category.id }}</td>
<td>{{ category.name }}</td>
<td style="width: 20%;">
<img :src="`${$store.state.baseUrl}/storage/${category.image}`" style="width: 100%;" :alt="category.name">
</td>
<td>
<button type="button" class="btn btn-danger" #click="deleteCategory(category)"><i class="fa fa-trash"></i></button>
<i class="fa fa-edit"></i>
</td>
</tr>
<tr v-else>
<th colspan="4" class="text-center">There's No Reacoards Yet</th>
</tr>
Is There Anyone Has A Solution For This Issue,
Thank You
- Muhammed Elfeqy
This is one of the times where you want to use the invisible <template> element
For example
<template v-if="categories.length > 0">
<tr v-for="category in categories" :key="category.id">
<!-- and so on -->
</tr>
</template>
<tr v-else>
<td colspan="4">There's No Records Yet</td>
</tr>

Vuejs - reading data from table

I'm trying to pull an updated value out of the table below to send it to database, but it appears that Vue does not support two-way data binding. Could anyone give me a hint on how I extract the current cell value and pass it to a function saving new data to a database?
<table v-if="tableData.length > 0" class="table table-bordered table-sm">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Date From</th>
<th scope="col">Date To</th>
<th scope="col">Days</th>
<th scope="col">Type</th>
<th scope="col">Request Date</th>
</tr>
</thead>
<tbody>
<tr v-for="(object, index) in tableData" :key="index">
<th scope="=row"><label class="tableNumberColumn">{{index + 1}}</label></th>
<td #change="readData" v-for="(value, key) in object" :key="key" v-if="key != 'formId'">
<div #change="readData" class="container tableColumnDiv" v-if="key === 'numberOfDays'" contenteditable="true">{{value}}</div>
<div class="container tableColumnDiv" v-else-if="key === 'timeOffType'" contenteditable="true">{{value}}</div>
<div v-else>
<datepicker :value="value" :bootstrap-styling="true"></datepicker>
</div>
</td>
<td>
<b-button #click="deleteRow(index)" class="btn btn-sm buttonDelete">Delete</b-button>
</td>
<td>
<b-button #click="update(index)" class="btn btn-sm buttonUpdate">Update</b-button>
</td>
<td>
<b-button class="btn btn-sm buttonPrint">Print</b-button>
</td>
</tr>
</tbody>
I am pasting the code one more time as I've removed some unnecessary stuff:
<table v-if="tableData.length > 0" class="table table-bordered table-sm">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Date From</th>
<th scope="col">Date To</th>
<th scope="col">Days</th>
<th scope="col">Type</th>
<th scope="col">Request Date</th>
</tr>
</thead>
<tbody>
<tr v-for="(object, index) in tableData" :key="index">
<th scope="=row"><label class="tableNumberColumn">{{index + 1}}</label></th>
<td v-for="(value, key) in object" :key="key" v-if="key != 'formId'">
<div class="container tableColumnDiv" v-if="key === 'numberOfDays'" contenteditable="true">{{value}}</div>
<div class="container tableColumnDiv" v-else-if="key === 'timeOffType'" contenteditable="true">{{value}}</div>
<div v-else>
<datepicker :value="value" :bootstrap-styling="true"></datepicker>
</div>
</td>
<td>
<b-button #click="deleteRow(index)" class="btn btn-sm buttonDelete">Delete</b-button>
</td>
<td>
<b-button #click="update(index)" class="btn btn-sm buttonUpdate">Update</b-button>
</td>
<td>
<b-button class="btn btn-sm buttonPrint">Print</b-button>
</td>
</tr>
</tbody>

Error TokenMismatchException in VerifyCsrfToken.php line 68:

I want to do multiple edit, I want to edit from the data I checked following script .blade, I found the TokenMismatchException error in VerifyCsrfToken.php line 68: when updating.
<form name="form" action="{{url('/update-kb')}}" method="post" onsubmit="return deleteConfirm();"/>
<div class="table table-responsive">
<table id="example1" class="table table-bordered">
<thead>
<tr class="info">
<th width="3%"><input type="checkbox" name="select_all" id="select_all" value=""/></th>
<th>No</th>
<th>Data lengkap</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
#foreach( $datasiswa as $row )
<tr>
<td>
<label class="checkbox-inline"><input type="checkbox" name="checked_id[]" class="checkbox" value="{{$row->id}}"/>
</label>
</td>
<td width="5%">{{ $i }}</td>
<td width="95%">
<table class="table">
<tr>
<td class="info">Nama panggilan</td>
<td>{{$row->nm_panggilan}}</td>
<td class="warning">Pekerjaan ibu</td>
<td>{{$row->pekerjaan_ibu}}</td>
</tr>
<tr>
<td class="info">Jenis kelamin</td>
<td>{{$row->jenis_kelamin}}</td>
<td class="warning">No. Handphone</td>
<td>{{$row->hp_ibu}}</td>
</tr>
<tr>
<td class="info">Tempat, Tanggal lahir</td>
<td>{{$row->tempat}}, {{$row->tanggal_lahir}}</td>
<td class="warning">Alamat</td>
<td>{{$row->alamat}}</td>
</tr>
<tr>
<td class="info">Status anak</td>
<td>{{$row->status_anak}}</td>
<td class="warning">Golongan darah</td>
<td>{{$row->goldar}}</td>
</tr>
<tr>
<td class="info">Agama</td>
<td>{{$row->agama}}</td>
<td class="warning">Nama wali</td>
<td>{{$row->nm_wali}}</td>
</tr>
<tr>
<td class="info">Kewarganegaraan</td>
<td>{{$row->kewarganegaraan}}</td>
</tr>
<tr>
<td class="info">Anak ke-</td>
<td>{{$row->anak_ke}}</td>
</tr>
<tr>
<td class="info">Kelas</td>
<td>{{$row->kelas}}</td>
</tr>
</table>
</td>
<td>
<a href="{!! url('/'.$row->id.'/edit-siswa') !!}">
<button class="btn btn-default btn-block"><i class="fa fa-edit"></i></button><br>
</a>
<a href="{!! url('/'.$row->id.'/delete-siswa') !!}">
<button class="btn btn-danger btn-block"><i class="fa fa-trash"></i></button>
</a>
</td>
</td>
</tr>
<?php $i++; ?>
#endforeach
</tbody>
</table>
<div class="col-md-3">
<input type="submit" class="btn btn-danger" name="delete_submit" value="Hapus"/>
</div>
</div>
</form>
But I still have error, what causes it?
public function updatekb($id, Request $request)
{
$data = Datasiswa::find($id);
if (isset($request->delete_submit)) {
$idArr = $request->checked_id;
foreach ($idArr as $id) {
DB::update('update tb_siswa, tb_pernyataan set tb_pernyataan.kelas = "cekcek" where tb_pernyataan.kelas = "TK A" and tb_siswa.sekolah = "KB TK KHALIFAH 25" and id = "' . $id . '" ');
}
return back();
Session::flash('sukses', 'Data berhasil di update', compact('data'));
}
}
Add below to your form element.
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
Some answers are suggesting to disable csrf protection which is possible but NOT RECOMENDED. This leaves your application vulnureable.
Laravel use CSRF token to verify user request. so you have to use it on yevery request if you want to disable it then you can disable it from See here how to disable it or you can use it as
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
You can resolve this issue in two ways:-
First One:-
{{ csrf_field() }}
or
<input type="hidden" name="_token" value="{{ csrf_token() }}"/> // add this in form
Or the other (simpler) way, inside your app\Http\Middleware/VerifyCsrfToken.php add
protected $except = [
'update-kb', // your route name
];
Hope it helps!