I want to create edit data on laravel using a modal for view .
but i dont know how to catch one data on on my edit form .
i build controller like edit data on another page ( not using modals )
public function index()
{
$ipsrs = DB::table('ipsrs')->pluck('nama_bagian','id');
$belum_kerjakan = Aduan::with('users')->where('status','Belum Dikerjakan')->get();
$dalam_proses = Aduan::with('users')->where('status','Sedang Dikerjakan')->get();
$selesai = Aduan::with('users')->where('status','Selesai')->get();
return view('admin.admin_dashboard',[
'belum_dikerjakan' => $belum_kerjakan,
'dalam_proses' => $dalam_proses,
'selesai' => $selesai,
'ipsrs' => $ipsrs,
]);
}
public function change_aduan($id)
{
$aduan = Aduan::findOrFail($id);
if (!$aduan)
abort(404);
return view('admin.admin_dashboard',[
'aduan' => $aduan
]);
}
this route . ( but i dont know where i used this route ?
Route::get('admin_dashboard', 'AdminController#index')->name('admin_dashboard'); // this route for view table
Route::get('change/{id}','AdminController#change_aduan')->name('change_aduan'); // this route "will" showing data on this modals
my View
<div class="card-body" align='center'>
<div class="card-body p-0">
<table class="table table-condensed">
<thead align="center">
<tr class="satu">
<th style="width: 3%">#</th>
<th style="width: 10%">Nama Unit</th>
<th style="width: 15%">Tanggal Aduan</th>
<th style="width: 8%">Nama Pengadu</th>
<th style="width: 8%">Tujuan Aduan</th>
<th style="width: 30%">Isi Aduan </th>
{{-- <th>Label</th> --}}
<th style="width: 5%">Status</th>
<th style="width: 5%">Action</th>
</tr>
</thead>
<tbody>
#php
$no=0;
#endphp
#foreach ($belum_dikerjakan as $i)
<tr>
<td> {{++$no}} </td>
<td> {{$i->users->nama_unit}}</td>
<td> {{$i->created_at}} </td>
<td> {{$i->nama_pengadu}} </td>
<td> {{$i->ipsrs->nama_bagian}} </td>
<td> {{$i->aduan}}</td>
<td><span class="badge bg-danger"> Belum Dikerjakan</span></td>
<td><button type="button" class="btn btn-default" data-toggle="modal" data-id="{{$i->id}}" data-target="#modal-lg" > // modals button
Action
</button></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="modal-lg">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"> Change Status </h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{-- Here this Form --}}
{{-- {{$aduan->nama_pengadu}} --}} // this Line is failur
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
i dont know how to next step , on another tutorial this data is can showed using {{ $data->name }} , but in my view cant do this . whats wrong ,and how i can solved this ?
I think you are not far off. I believe the issue you are having is that you are trying to pull the name field from a collection instead of an object.
In your Blade file, this line:
<td> {{$i->users->nama_unit}}</td>
is essentially saying: for this iteration ($i) of $belum_dikerjakan, give me ALL the users and tell me the name of the collection of users. The collection doesn't have a name field. Because you have many users for this $belum_dikerjakan, you will either need to loop on all of them, identify the specific user by id (example $i->users->where('id', 1)->first()->nama_unit), or take the first one randomly:
$i->users->first()->nama_unit
What these examples do, is it pulls a single object user instead of a collection, and thus you have the field name on that object.
This line:
<td> {{$i->ipsrs->nama_bagian}} </td>
doesn't look like a relationship at all, and you may need to refactor this into either a relation on $belum_dikerjakan, or remove it from the loop and use it independently, but this is a separate issue I think.
Hope this helps.
Related
I am using the angular material 12 version drag and drop feature. I have two connected divs while dropping the item I want to identify whether the source (item dragged container) container and target container(item dropped container) are the same or not.
Thanks in advance. please find below the code
<div class="toc_listing" cdkDropList [cdkDropListData]="table_list" [cdkDropListConnectedTo]="table_toc"
#list_toc="cdkDropList" (cdkDropListDropped)="drop($event)">
<p *ngFor="let item of table_list" cdkDrag>
<span class="icons"><i class="fa fa-ellipsis-v" aria-hidden="true"></i>
<i class="fa fa-ellipsis-v" aria-hidden="true"></i></span>
<span class="list-no">{{item.tableNo}}</span>
<span class="list-name">{{item.name}}</span>
</p>
</div>
<div class="table responsive-table">
<table class="table">
<thead>
<td>t.no</td>
<td>name</td>
<td>type</td>
<td>population</td>
<td>actions</td>
</thead>
<tbody cdkDropList [cdkDropListData]="toc_list"
#table_toc="cdkDropList" (cdkDropListDropped)="drop($event)">
<tr *ngFor="let item of toc_list" cdkDragLockAxis="x" cdkDragLockAxis="y" class="dragdrop_table">
<td>{{item?.tlfTocMasterDto?.tableNo}}</td>
<td (click)="viewEditor(item)" data-toggle="tooltip" [matTooltip]="item.selected ? 'Edit Mockshell':'Mockshell is not selected'">{{item?.tlfTocMasterDto?.name}}</td>
<td>{{item?.tlfTocMasterDto?.tableType}}</td>
<td>{{item?.tlfTocMasterDto?.population}}</td>
<td>
<p class="edit" data-bs-toggle="modal" data-bs-target="#editTableOfContent" *ngIf="!item.selected" (click)="editTable(item)"><i class="fa fa-pencil" aria-hidden="true"></i>
</p>
<p class="delete" (click)="deleteTable(item, $event)" *ngIf="!item.selected"><i class="fa fa-trash-o" aria-hidden="true"></i></p>
</td>
</tr>
</tbody>
</table>
</div>
The CdkDragDrop parameter contains the container (dropped container) and previousContainer which you can compare directly
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
...your logic
}
}
I was having another laravel question here. I was facing 404 error when clicking the button
Confirm Registration on the purpose of changing its database based on the item id on the view. Logically, I think my code should have work on this part.
Confirm Registration
However, it comes up 404 Error. Herby I include all the related code in the section.
Error
Frontend (To prove that the data passing is successful in the view)
web.php
Route::controller(ResidenceController::class)->group(function(){
Route::get('/residence/register', 'registration')->name('residence.register');
Route::get('/residence/search', 'SearchProperty')->name('residence.search');
Route::get('/registration/confirmation/{$uniquecode}', 'ConfirmRegistration')->name('registration.confirm');
});
The focus is on:
Route::get('/registration/confirmation/{$uniquecode}',
'ConfirmRegistration')->name('registration.confirm');
Controller
public function ConfirmRegistration($uniquecode){
$confirm = Properties::where('uniquecode', $uniquecode)->update(['status'=>'pending', 'tenant_id'=>Auth::user()->id]);
if($confirm){
session()->flash('alert-success','Successfully Applied');
}
else{
session()->flash('alert-warning','Error Occured');
}
}
register.blade.php
#foreach ($toSearch as $key=>$view)
<div class="card" style="width: 50rem;">
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-md-3">
<img src="{{ (!empty($tenant->unit_image))? url('uploads/properties/'.$tenant->unit_image):url('uploads/properties/default.jpg') }}" class="img-fluid" alt="unit image" >
</div>
<div class="col-md-9">
<table>
<tr>
<td style="width: 20%">Property</td>
<td style="width:10%; text-align: center">:</td>
<td>{{$view->name}}</td>
</tr>
<tr>
<td>Address</td>
<td style="text-align: center">:</td>
<td>{{$view->address1}},{{$view->address2}},{{$view->city}}</td>
</tr>
<tr>
<td>Landlord</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->name}}</td>
</tr>
<tr>
<td>Contact No</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->phone_number}}</td>
</tr>
<tr>
<td>Status</td>
<td style="text-align: center">:</td>
<td>{{$view->status}}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<br>
<!--To confirm registration-->
#if( $view->status != 'approved')
Confirm Registration
#endif
</div>
#endforeach
The focus is on:
#if( $view->status != 'approved')
uniquecode) }}" class="btn btn-primary">Confirm
Registration
#endif
Database:
you need to use post method for inserting data (register),
anyway, change your route parameter $uniquecode to uniquecode.
and when you use route second argument is a compact, use
route('registration.confirm',['uniquecode' => $view->uniquecode]);
i have a multiple pages application that i build in Laravel, i want to use Vuejs in some parts of the application.i have six modules customers,invoice,products,stocks,dashboard,analysis.
The customers,products,stock are just basic crud so i use Laravel.
How to do i turn the invoice,analysis,dashboard in single page applications. i have tried but when i use chromes back arrow to redirect back, i get 404|page not found.
this is my invoice/index.blade.php file, it loads everything corrently
<div class="row">
<div class="col-md-12">
<invoice-index></invoice-index>
</div>
</div>
inside my component, when i click on any link i a 404 error. i have tried router-link , 'a href' none is redirecting me to invoiceform
<template>
<div class="row">
<div class="col-md-12">
<div class="tile">
<div class="row pb-3">
<div class="col-md-12">
<div class="tile-header">
new Invoice
</div>
</div>
</div>
<div class="tile-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th> # </th>
<th style="with:20%"> Date </th>
<th> Number </th>
<th> Customer </th>
<th> Due Date </th>
<th> Total </th>
<th style="width:100px; min-width:100px;" class="text-center text-danger"><i class="fa fa-bolt"> </i></th>
</tr>
<tr v-for="invoice in allInvoices" :key="invoice.id" class="py-0 text-center" >
<td class="align-middle py-0">
<a href="#" class="nav-link text-info font-weight-bold">
{{ invoice.id }}
</a>
</td>
<td style="width: 10%">{{invoice.date}}</td>
<td >{{invoice.number}}</td>
<td >{{invoice.customer_id}}</td>
<td >{{invoice.due_date}}</td>
<td >{{invoice.total}}</td>
<td class="text-center">
<div class="btn-group" role="group" aria-label="Second group">
<i class="fa fa-edit"></i>
<i class="fa fa-trash"></i>
</div>
</td>
</tr>
</thead>
</table>
</div>
</div>
</div>
I this is my routes
const router = new VueRouter({
routes: [
{
path:'/dashboard',
component: DashboardComponent
},
{
path:'/invoices',
component: InvoiceIndex
},
{
path:'/invoices/create',
component: InvoiceForm
}
],
mode:'history'
});
For SPA with Vue.js, You must define links using vue-router. When defined routes using vue-router, you can use your vue.js routes and only calls components. So you can build SPA. You can find details on here.
https://router.vuejs.org/
I hope it helps you. But It can be hard to implement if you are new on Vue.js
I have table data , its showing data from database .
i want to showing data with Action and its will showing Modal and data .
my view like this :
<div class="table-responsive">
<table class="table table-striped jambo_table bulk_action" id="table2">
<thead>
<tr class="headings">
<th class="column-title" style="display: table-cell;">No </th>
<th class="column-title" style="display: table-cell;">Nama Pegawai </th>
<th class="column-title" style="display: table-cell;">Lihat Data Keluarga </th>
</tr>
</thead>
<tbody>
#php
$no=0;
#endphp
#foreach ($keluarga as $i)
<tr class="even pointer">
<td class="a-center ">{{ ++$no }}</td>
<td class=" ">{{ $i->users->nama}} </td>
<td class=" "><a href="/project/d_keluarga/show-keluarga/{{$i->id}}"><button type="button" class="btn btn-danger" data-toggle="modal" data-target=".bs-example-modal-lg"> Show Data</button> // to showing data By Id on table
</td>
</tr>
#endforeach
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">Data Keluarga</h4>
</div>
<div class="modal-body">
<h4></h4>
//here to paste data
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</tbody>
</table>
</div>
My Controller :
public function keluarga()
{
$keluarga = Data_keluarga::with('users')->get();
return view('admin.keluarga',['keluarga' => $keluarga ]);
}
i usually parse it like $i->name and its in another page . not in Modal .
but , how to show data in modal by id ?
Here's an answer for your exact question.
Add data-title="{{ $i->users->nama }}" to your button.
<button type="button" class="btn btn-danger" data-toggle="modal" data-target=".bs-example-modal-lg" data-title="{{ $i->users->nama }}"> Show Data</button>
Add this jQuery snippet.
$('.bs-example-modal-lg').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var title = button.data('title')
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text(title)
})
I am new to Laravel. I am trying to create pagination with the data in my bootstrap table.
This is my index Controller function:
$Courses=Courses::orderBy('name','desc')->paginate(1);
return view('Courses.index')->with('Courses',$Courses);
I am getting this error:
Call to undefined method App\Courses::links() (View:
C:\laragon\www\TharakaCollege\resources\views\Courses\index.blade.php)
The information provided is not enough, however I think the problem is in your view. You have to have a code like this in your blade file:
<div class="pages">
<ul class="pagination ">
<li>{{$Courses->appends(request()->query())->links()}}</li>
</ul>
</div>
Moreover you'd better edit your returning view like this:
return view('Courses.index', array('Courses'=> $Courses));
This is the code in Courses/index.blade.php
<div id="page-wrapper">
#include('includes.message');
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
Courses
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center"> code</th>
<th class="text-center">Course Name</th>
<th class="text-center">Category</th>
<th class="text-center">Requirements</th>
</tr>
</thead>
<tbody>
#if(count($Courses)>0)
#foreach($Courses as $Courses)
<tr class="item{{$Courses->id}}">
<td>{{$Courses->id}}</td>
<td>{{$Courses->code}}</td>
<td>{{$Courses->name}}</td>
<td>{{$Courses->category}}</td>
<td>{{$Courses->requirements}}</td>
<td><a class="btn btn-info btn-sm" href="/Courses/{{$Courses->id}}/edit">Edit</a>
</td>
<td>
<form method="POST" action="{{route('Courses.destroy',$Courses->id)}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" class="btn btn-danger btn-sm" value="Delete">
</form>
</td>
</tr>
#endforeach
#else
<p>No Courses</p>
#endif
</tbody>
</table>
{{ $Courses->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
You should try this:
<div class="pull-left">
<div class="row">
<div class="col-xs-12">
<div class="explore-pagination">
<nav>
<div class="pagination"> {{ $Courses->render() }}</div>
</nav>
</div>
</div>
</div>
</div>
Try this code instead (modified version of yours):
<div id="page-wrapper">
#include('includes.message');
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
Courses
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center"> code</th>
<th class="text-center">Course Name</th>
<th class="text-center">Category</th>
<th class="text-center">Requirements</th>
</tr>
</thead>
<tbody>
#if(count($Courses)>0)
#foreach($Courses as $Course)
<tr class="item{{$Course->id}}">
<td>{{$Course->id}}</td>
<td>{{$Course->code}}</td>
<td>{{$Course->name}}</td>
<td>{{$Course->category}}</td>
<td>{{$Course->requirements}}</td>
<td><a class="btn btn-info btn-sm" href="/Courses/{{$Course->id}}/edit">Edit</a>
</td>
<td>
<form method="POST" action="{{route('Courses.destroy',$Course->id)}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" class="btn btn-danger btn-sm" value="Delete">
</form>
</td>
</tr>
#endforeach
#else
<p>No Courses</p>
#endif
</tbody>
</table>
{{$Courses->appends(request()->query())->links()}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I have modified your foreach loop as well as ->links().
When calling the paginate method, you will receive an instance of Illuminate\Pagination\LengthAwarePaginator. In addition to these helpers methods, the paginator instances are iterators and may be looped as an array. So, once you have retrieved the results, you may display the results and render the page links using Blade:
Your blade should contain:
<div class="container">
#foreach ($courses as $course)
{{ $course->fieldName }}
#endforeach
</div>
{{ $courses->links() }}