i want to update data "barang" using pop up.
before the pop up goes down completely, the page redirect http://localhost/koperasi/index.php/cukl/undefined & show
" The page you requested was not found" error.
....
this is my controller
public function ubahbarang(){
if ($this->input->post('ubahdatabarang')) {
$id_barang=$this->input->post('id_barang');
$id_jenis=$this->input->post('id_jenis');
$nm_barang=$this->input->post('nm_barang');
$stok=$this->input->post('stok');
$hrg_beli=$this->input->post('hrg_beli');
$hrg_jual=$this->input->post('hrg_jual');
$this->barang->mengubah_barang($id_barang, $id_jenis, $nm_barang, $stok, $hrg_beli, $hrg_jual);
redirect('cukl', 'refresh');
}
}
....
this is my model
public function mengubah_barang($id_barang, $id_jenis, $nm_barang, $stok, $hrg_beli, $hrg_jual)
{
$hasil = $this->db->query("UPDATE barang SET id_barang='$id_barang', id_jenis='$id_jenis', nm_barang='$nm_barang', stok='$stok',
hrg_beli='$hrg_beli', hrg_jual='$hrg_jual'");
return $hasil;
}
...
this is table view which I use to update data using popups
<table class="table table-borderless table-striped table-earning">
<h2>BARANG</h2><br>
<thead>
<tr>
<th>ID BARANG</th>
<th>ID JENIS</th>
<th>NAMA BARANG</th>
<th class="text-right">STOK</th>
<th class="text-right">HARGA BELI</th>
<th class="text-right">HARGA JUAL</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($barang as $i): ?>
<td><?=$i->id_barang;?></td>
<td><?=$i->id_jenis;?></td>
<td><?=$i->nm_barang;?></td>
<td><?=$i->stok;?></td>
<td><?=$i->hrg_beli;?></td>
<td><?=$i->hrg_jual;?></td>
<td style="text-align: center">
<a data-toggle="modal" data-target="#modal_edit<?= $i->id_barang;?>" class="btn btn-success">
<i class="fa fa-pencil" color="white"></i>Ubah
</a>
</td>
</tr>
</tbody>
<?php endforeach ?>
</table>
and this is the popups code
(sorry i cant write it one the page :(( )here is the pict
Opening
Closing
just in case the source code
( https://drive.google.com/open?id=1LbKScF65ej2kT0iQfhU2egBwAGWGA7Ee )
You have used redirect('cukl', 'refresh'); to redirect
Redirect goes in ways :-
redirect('control_name/method_name','refresh')
Your Code is right,but I think there is problem with routing.
You can try it by 301 redirect
redirect('/cukl', 'location', 301);
if still problem not solved please provide .htaccess and config/routes.php here.
Related
I have a simple table in my Codeigniter site like below
<table class="table">
<thead>
<tr>
<th>Time</th>
<th>Image</th>
<th>Username</th>
<th>Comment</th>
<th>Action</th>
</tr>
</thead>
<tbody id="ajax_table">
</tbody>
</table>
and I am displaying row like below
public function getComment(){
$page = $_GET['page'];
$user_id =$_GET['user_id'];
// $data['comments'] = $this->member->get_all_comment($user_id);
$comments = $this->member->get_all_comment($page,$user_id);
$html='';
if(isset($comments) && count($comments)>0){
foreach($comments as $comment){
if($comment->image ==""){
$image = "https://granboardonline.com/uploads/empty.jpg";
}
else {
$image = "https://granboardonline.com/uploads/".$comment->image;
}
$html.= "<tr><td>".$comment->date_created."</td><td> <img src= $image style='width:50px;height:50px;'> </td><td>".$comment->fname."</td><td>".$comment->comment."</td>";
if($this->session->userdata('user_id')==$comment->reciver_id || $this->session->userdata('user_id')==$comment->sender_id){
$html.="<td><button class='btn btn-light btn-sm deletecomment' comment_id='".$comment->comment_id."'>Delete</button></td></tr>";
}
}
}
echo $html;
exit;
}
But my comment column's row going outside and looking very bad, How I can show it fit the column?
Thanks!
You can refer https://www.w3schools.com/bootstrap4/bootstrap_tables.asp and
https://getbootstrap.com/docs/4.0/content/tables/ for more information.
<div class="table-responsive">
<table class="table">
...
</table>
</div>
It's always a good practice to set the width of the columns to give more look and feel to the design and avoid taking auto width as per the content.
If you are not using bootstrap table utility classes then remember that your table should have the width 100% and there should be an overflow if the page is opened in the smaller devices to avoid inconsistency in the width of the page.
You can do that by enclosing it inside a div
<div style="overflow:auto">
<table class="table" style="width:100%;">
...
</table>
</div>
I hope that helps you.
use word-break style for td tag
e.g
<td style="word-break: break-word;">aaaaaaaaaaaaaaaaaaaaaaaa</td>
I'm new ton Laravel (also to StackOverflow), and I'm trying to show data in my home.blade.php table from PhpMyAdmin using a foreach loop. However, it's not working correctly, and I can't figure out where the problem is. I have other tables working with foreach, and I've followed the same steps with this table.
User Model
protected $table = 'users';
protected $fillable = ['id','name','edad','direccion_personal','celular','foto','email','direccion_sucursal_id'];
UserController
public function index()
{
$Usuarios = User::all();
$array = ['usuarios' => $Usuarios];
return view('home')->with($array);
}
Finally, here's my tbody:
<tbody>
#foreach ($usuarios as $Usuarios)
<div>
<tr>
<th scope="row" style="text-align:center;">{{ $Usuarios->id }}</th>
<td style="text-align:center;">{{ $Usuarios->nombre }}</td>
.
.
.
</tr>
</div>
</tbody>
#endforeach
Why the array?
public function index(){
$usuarios = User::all();
return view('home', compact('usuarios'));
}
Then:
<tbody>
#foreach ($usuarios as $us)
<div>
<tr>
<th scope="row" style="text-align:center;">{{$us->id}}</th>
<td style="text-align:center;">{{$us->nombre}}</td>
.
.
.
</tr>
</div>
#endforeach
</tbody>
I see you're having troubles with the foreach loop. is not working correctly... but, I'm not sure what kind of problem is... if my answer does not work for you, please update your question so you can get more help
I see you close your inside the foreach loop.
That way you will end with lots of closing tags with just one opening...
Try moving that close tag outside the loop
<tbody>
#foreach ($usuarios as $Usuarios)
<div>
<tr>
<th scope="row" style="text-align:center;">{{$Usuarios->id}}</th>
<td style="text-align:center;">{{$Usuarios->nombre}}</td>
.
.
.
</tr>
</div>
#endforeach
</tbody>
Your foreach closes outside the </tbody> tag, and opens inside it. Your table body is thus closed after the first iteration of the loop, and never opened again, so with each iteration you now have an additional </tbody> line. This is invalid markup, and will break your site's output.
Trying to delete from my API which is hosted on Heroku.
In Ruby file CROSS-ORIGIN is enable and I can get information from my API.
Although I have a problem when I want to make a delete request to the server.
I get an error 404 (Page not found), but when typing the url into the browser myself I can easily get this page.
cURL call works fine without any problems too.
script.js
$scope.DeleteData = function (index) {
$scope.id = $scope.companies[index].companyID;
var deleteUrl = 'https://*****.herokuapp.com/api/v1/companies/' + $scope.id;
$http.delete(deleteUrl,'DELETE').then(function(response){
console.log(response);
},function(errorResponse){
console.log(errorResponse);
});
};
Ruby.rb
delete '/companies/:companyID' do
tempCompanyID = params['companyID']
company = Company.where(companyID: tempCompanyID).first
company.destroy
end
Html:
<div ng-app="myApp" ng-controller="companyCtrl">
<table class="table table-striped table-hover">
<thead class="thead-dark">
<th>Company ID</th>
<th>Company Name</th>
<th>Address</th>
<th>City</th>
<th>Country</th>
<th>Owners</th>
<th></th>
</thead>
<tr ng-repeat="company in companies">
<td>{{company.companyID}}</td>
<td>{{company.companyName}}</td>
<td>{{company.address}}</td>
<td>{{company.city}}</td>
<td>{{company.country}}</td>
<td>{{company.owners}}</td>
<td><button class="btn" name="_method" ng-click="DeleteData($index)">Delete</button></td>
</tr>
</table>
</div>
Chrome response:
The response
I try to create a table that containt checkbox using laravel blade .
But checkbox does not appear in the table.
this is my code:
#section('content')
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>Survey</th>
<th>Date</th>
<th>Published</th>
<th>Creator</th>
<th>seen</th>
</tr>
</thead>
<tbody>
#foreach($surveys as $survey)
<tr {!! !$survey->seen && session('statut') == 'admin'? 'class="warning"' : '' !!}>
<td>{{$survey->title}}</td>
<td>{{$survey->created_at->todatestring()}}</td>
<td>{!! Form::checkbox('active', $survey->id, $survey->active) !!}</td>
#foreach($users as $user)
#if($user->id == $survey->user_id)
<td>
{{$user->name}}
</td>
#endif
#endforeach
<td>{!! Form::checkbox('seen', $survey->id, $survey->seen) !!}</td>
<td><button type="button" class="btn btn-info">Detail</button></td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endsection
help me please!thank you in advance
Please use in this way.
{{ Form::checkbox('agree', 'yes') }}
Refer to this URL
I've tried your code and the checkbox works fine without problem as long as you already done all of this things correctly.
Install & setup Laravel Collective (https://laravelcollective.com/docs/master/html)
$surveys already sent from your controller with its data
$survey->seen contains boolean value (true/false)
I want to display the database values depending on the particular ID. I pass that id in the URL, and it redirects to another page with ID. In that page I have to display that particular user's records.
Here is the controller function:
public function consultants()
{
return view('Hr/view-request-candidates', [
'consultant' => HrRequestConsultant::all(),
]);
}
Route:
Route::get(
'/view-request-candidates/{hr_request_id}',
'Hr\HrDashboardController#consultants'
);
URL:
CANDIDATES
View:
<div class="col-md-12">
<table class="table table-striped">
<tbody>
<tr>
<th>Hr Request ID</th>
<th>Consultant ID</th>
<th>No Of Candidates</th>
<th>Actions</th>
</tr>
#foreach($consultant as $row)
<tr>
<td>{{$row->hr_request_id}}</td>
<td>{{$row->consultant_id}}</td>
<td>{{30}}</td>
<td>
<a href="/view-hr-candidates" class="btn btn-primary">View</button>
</td>
</tr>
#endforeach
How can I do this?
Routes::
Route::get('home','HrDashboardController#home');
Route::get('view-hr-candidates/{hr_request_id}','HrDashboardController#consultants');
Controller::
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\HrRequestConsultant;
use DB;
class HrDashboardController extends Controller
{
public function home(){
$home = HrRequestConsultant::select('id','hr_request_id','consultant_id')->get();
return view('home')->with('home', $home);
//Its View: home.blade.php file
}
public function consultants($id){
$result = HrRequestConsultant::select('id','hr_request_id','consultant_id')->where('hr_request_id',$id)->first();
return $returnview = view('Hr.view-request-candidates')->with('result', $result);
// Its view-request-candidates.blade.php file InSide the Hr Dir.
}
}
home.blade.php::
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md"> View Details </div>
<div class="col-md-12">
<table border="1" style='color: black'>
<tr>
<th>Hr Request ID</th>
<th>Consultant ID</th>
<th>No Of Candidates</th>
<th>Actions</th>
</tr>
#foreach ($home as $data){
<tr>
<td> {{ $data['hr_request_id'] }} </td>
<td> {{ $data['consultant_id'] }} </td>
<td> 30 </td>
<td> View </td>
</tr>
#endforeach
</table>
</div>
</div>
</div>
</body>
view-request-candidates.blade.php
<h1> Hello .. This Is Request Id: {{ $result['hr_request_id'] }} </h1>
<br>
<h1> Hello .. This Is Consultant Id: {{ $result['consultant_id'] }} </h1>
To get the single record use the find method instead of all:
public function consultants($id)
{
return view('Hr/view-request-candidates', [
'consultant' => HrRequestConsultant::find($id),
]);
}
It is best practice to name the route and use name wherever you need that route. So change the route like this :
Route::get(
'/view-request-candidates/{hr_request_id}',
'Hr\HrDashboardController#consultants')->name('view.consultant');
Remove the foreach loop from your view and change the route to named route:
<div class="col-md-12">
<table class="table table-striped">
<tbody>
<tr>
<th>Hr Request ID</th>
<th>Consultant ID</th>
<th>No Of Candidates</th>
<th>Actions</th>
</tr>
<tr>
<td>{{$consultant->hr_request_id}}</td>
<td>{{$consultant->consultant_id}}</td>
<td>{{30}}</td>
<td>
<a href="{{ route('view.consultant', ['hr_request_id' => $consultant->hr_request_id]) }}" class="btn btn-primary">View</button>
</td>
</tr>