Angularjs ng-click not working in laravel #PHP - php

I have just created a very simple app. It only contains one function which is used in ng-click. Somehow, ng-click is not firing. Can anyone take a look for me?
<div class="form-inline">
<label for="primary" style="padding-right:5px">Primary skill </label>
<select id="primary" class="form-control" ng-model="primary" id="primary" ng-options="s.skill_name for s in skills| excludeFrom:secondary"></select>
<label for="secondary">Secondary skill </label>
<select id="secondary" class="form-control " id="secondary" ng-model="secondary" ng-options="s.skill_name for s in skills| excludeFrom:primary"></select>
<div ng-controller="profileController">
<input type="button" value="Search" class="mx-sm-3 btn btn-primary" ng-model="searchbtn" name="search" ng-click="profileController.getprofile()">
<table class="table" id="myTable">
<tr>
<th>Full name</th>
<th>Email</th>
<th>City</th>
<th>Primary skill1</th>
<th>Primary skill2</th>
<th>Primary skill3</th>
<th>Secondary skill1</th>
<th>Secondary skill2</th>
<th>Secondary skill3</th>
<th>Secondary skill4</th>
<th>Secondary skill5</th>
</tr>
<tr ng-repeat="p in profiles">
</tr>
</table>
</div>
</div>
<script>
function profileController($scope, $http) {
$scope.getprofile = function() {
var pskill = $("#primary").val();
var skill = $("#secondary").val();
$http({
url: "{{PROFILE_REPOSITORY}}",
method: "POST",
data: { "_token": { { csrf_token() } }, 'primary': pskill, 'secondary': skill },
}).then(function(response) {
$scope.profiles = response.data;
console.log(response.data);
}),
function(response) {
console.log('failed');
}
}
}
</script>

<div class="form-inline">
<label for="primary" style="padding-right:5px">Primary skill </label>
<select id="primary" class="form-control" ng-model="primary" id="primary" ng-options="s.skill_name for s in skills| excludeFrom:secondary"></select>
<label for="secondary">Secondary skill </label>
<select id="secondary" class="form-control " id="secondary" ng-model="secondary" ng-options="s.skill_name for s in skills| excludeFrom:primary"></select>
<div ng-controller="profileController">
<input type="button" value="Search" class="mx-sm-3 btn btn-primary" ng-model="searchbtn" name="search" ng-click="getprofile()">
<table class="table" id="myTable">
<tr>
<th>Full name</th>
<th>Email</th>
<th>City</th>
<th>Primary skill1</th>
<th>Primary skill2</th>
<th>Primary skill3</th>
<th>Secondary skill1</th>
<th>Secondary skill2</th>
<th>Secondary skill3</th>
<th>Secondary skill4</th>
<th>Secondary skill5</th>
</tr>
<tr ng-repeat="p in profiles">
</tr>
</table>
</div>
</div>
<script>
function profileController($scope, $http) {
$scope.getprofile = function() {
var pskill = $("#primary").val();
var skill = $("#secondary").val();
$http({
url: "{{PROFILE_REPOSITORY}}",
method: "POST",
data: { "_token": { { csrf_token() } }, 'primary': pskill, 'secondary': skill },
}).then(function(response) {
$scope.profiles = response.data;
console.log(response.data);
}),
function(response) {
console.log('failed');
}
}
}
</script>

Related

How to to quickly load session data in ajax or JQuery?

Please I have products(Cart) in session but loads very slow on server anytime I reload a table to display items added to the cart. How do I quickly display session data using ajax or JQuery? Kindly assist.After adding Item to cart. $("#tabler").load(" #tabler") Loads slowly. Please is there any better way to do this.
$("#newinvoice").on('submit', function(event) {
event.preventDefault();
$.ajax({
type: "post",
url: "{{route('InvoiceDump')}}",
dataType: "json",
data: $('#newinvoice').serialize(),
success: function(data){
document.getElementById('price').value = "";
document.getElementById('total').value = "";
document.getElementById('quantity').value = "1";
document.getElementById('ddlViewBy').value = "";
$("#tabler").load(" #tabler");
},
error: function(data){
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong!',
footer: 'Why do I have this issue?'
})
}
});
});
My Table
<table class="table table-bordered table-striped m-0">
<thead>
<tr>
<th colspan="7" class="pt-3 pb-3">Invoice Details</th>
</tr>
<tr>
<th width="50%">Product</th>
<th width="50%">Category</th>
<th>Quantity</th>
<th width="20%">Price</th>
<th width="30%">Amount (Net)</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($cartItems as $key => $cart)
<tr>
<td><select class="form-control"><option>{!!#strtoupper($cart['invoice_product_name'])!!}</option></select></td>
<td><input type="text" value="{{#strtoupper($cart['item_category'])}}" class="form-control" readonly></td>
<td>
<!-- Field wrapper start -->
<div class="field-wrapper m-0">
<input type="text" readonly class="form-control" value="{{empty($app->currency) ? "GHS" : $app->currency}}#convert($cart['invoice_quantity'])" placeholder="Qty">
</div>
<!-- Field wrapper end -->
</td>
<td>
<!-- Field wrapper start -->
<div class="field-wrapper m-0">
<input type="text" readonly class="form-control" value="{{empty($app->currency) ? "GHS" : $app->currency}}#convert($cart['invoice_unit_price'])">
</div>
<!-- Field wrapper end -->
</td>
<td>
<!-- Field wrapper start -->
<div class="field-wrapper m-0">
<input type="text" readonly class="form-control" value="{{empty($app->currency) ? "GHS" : $app->currency}}#convert($cart['invoice_total_price'])">
</div>
<!-- Field wrapper end -->
</td>
<td>
<div class="table-actions">
<button class="btn btn-light" id="{{$cart['id']}}" onClick="DeleteItem(this.id)">
<i class="icon-trash-2"></i>
</button>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>

Laravel Ajax Search Query Param Issue

Trying to create/learn ajax search results using Laravel. Im at the following stage where I can get the data from the DB but the query string appears to not be captured into the controller and querying the data. I expect its an issue with my Ajax or where I am posting the data from the view to the URL. I am new to Laravel so any advice will be welcome. Thanks
search.blade.php
<form class="navbar-search">
<div class="input-group">
<input type="text" class="form-control bg-lightblue border-0 small text-white border-dark" name="search" id="search" placeholder="Search for..." aria-label="Search" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-success" type="button"></button>
</form>
<div class="col-md-12">
<table class="table table-hover table-responsive-sm">
<thead class="thead-dark">
<tr>
<th scope="col">Total Data : <span id="total_records"></span></th>
<th scope="col">Company Name</th>
<th scope="col">Immediate Contact</th>
<th scope="col">Address</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
fetch_customer_data();
function fetch_customer_data(query = '')
{
$.ajax({
url:"{{ route('search.action') }}",
//url: 'user-figures/action',
method: 'GET',
data: {"query":query},
dataType:'json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success:function(data)
{
$('tbody').html(data.table_data);
$('#total_records').text(data.total_data);
}
})
}
});
</script>
Controller
public function ajaxindex()
{
return view('search.index');
}
public function ajaxaction(Request $request)
{
if($request->ajax())
{
$total_row = '';
$output = '';
$query = $request->get('query');
if($query != '')
{
$data = figures::where('name', 'like', '%'.$query.'%')
->get();
}
else
{
$data = figures::orderBy('id', 'desc')
->get();
}
$total_row = $data->count();
if($total_row > 0)
{
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->name.'</td>
<td>poopppp</td>
</tr>
';
}
}
else
{
$output = '
<tr>
<td colspan="5">No Data Found</td>
</tr>
';
}
$data = array(
'table_data' => $output,
'total_data' => $total_row
);
return response()->json($data);
// $str_data = implode(" ", $data);
// echo $str_data;
}
}
web.php
Route::get('/search', 'figuresController#ajaxindex')->name('search');
Route::get('/search/action', 'figuresController#ajaxaction')->name('search.action');
I used your code and followed this tutorial https://www.cloudways.com/blog/live-search-laravel-ajax/ and have got this to work. Here is my full code and hopefully you can figure out how to get yours working
Search controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Product;
class SearchController extends Controller
{
public function index()
{
return view('search.index');
}
public function search(Request $request)
{
if($request->ajax())
{
$output="";
$products=DB::table('products')->where('title','LIKE','%'.$request->search."%")->get();
if($products)
{
foreach ($products as $key => $product) {
$output.='<tr>'.
'<td>'.$product->id.'</td>'.
'<td>'.$product->title.'</td>'.
'<td>'.$product->description.'</td>'.
'<td>'.$product->price.'</td>'.
'</tr>';
}
return Response($output);
}
}
}
}
Just one view file
<!DOCTYPE html>
<html>
<head>
<meta name="_token" content="{{ csrf_token() }}">
<title>Live Search</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Products info </h3>
</div>
<div class="panel-body">
<div class="form-group">
<input type="text" class="form-controller" id="search" name="search"></input>
</div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#search').on('keyup',function(){
$value=$(this).val();
$.ajax({
type : 'get',
url : '{{URL::to('search/action')}}',
data:{'search':$value},
success:function(data){
$('tbody').html(data);
}
});
})
</script>
<script type="text/javascript">
$.ajaxSetup({ headers: { 'csrftoken' : '{{ csrf_token() }}' } });
</script>
</body>
</html>
Routes
Route::get('/search','SearchController#index');
Route::get('/search/action','SearchController#search')->name('search.action');

AdminLTE Pagination - Where to Start?

I'm building a web database application in PHP PDO using the AdminLTE template and Booststrap 3.
I need to add pagination to my application (as I have a large amount of records) and have a limit of 25 records per page. I am fairly new at programming and have no idea where to start. Any help would be appreciated.
<?php
$content = '<div class="row">
<div class="col-xs-12">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title">Members List</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="members" class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Residential Address</th>
<th>Mailing Address</th>
<th>Precinct</th>
<th>Age</th>
<th>Ethnicity</th>
<th>Gender</th>
<th>Party</th>
<th>Race</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Residential Address</th>
<th>Mailing Address</th>
<th>Precinct</th>
<th>Age</th>
<th>Ethnicity</th>
<th>Gender</th>
<th>Party</th>
<th>Race</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>';
include('../master.php');
?>
<!-- page script -->
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "../api/member/read.php",
dataType: 'json',
success: function(data) {
var response="";
for(var user in data){
response += "<tr>"+
"<td>"+data[user].name+"</td>"+
"<td>"+data[user].residential_address+"</td>"+
"<td>"+data[user].mailing_address+"</td>"+
"<td>"+data[user].precinct+"</td>"+
"<td>"+data[user].age+"</td>"+
"<td>"+data[user].ethnicity+"</td>"+
"<td>"+data[user].gender+"</td>"+
"<td>"+data[user].party+"</td>"+
"<td>"+data[user].race+"</td>"+
"<td>"+data[user].phone+"</td>"+
"<td><a href='update.php?id="+data[user].id+"'>Edit</a> | <a href='#' onClick=Remove('"+data[user].id+"')>Remove</a></td>"+
"</tr>";
}
$(response).appendTo($("#members"));
}
});
});
function Remove(id){
var result = confirm("Are you sure you want to delete the selected member from the database?");
if (result == true) {
$.ajax(
{
type: "POST",
url: '../api/member/delete.php',
dataType: 'json',
data: {
id: id
},
error: function (result) {
alert(result.responseText);
},
success: function (result) {
if (result['status'] == true) {
alert("The member was successfully removed from the database.");
window.location.href = '/ccrp/members';
}
else {
alert(result['message']);
}
}
});
}
}
</script>

ngClick not working to multiple buttons using CodeIgniter framework

I'm new to Angularjs. I'm trying to call function onclick of the buttons. I used ng-click but it's not working. These buttons are dynamically created.
I'm implementing this application in CodeIgniter framework. Here is my code;
//view
<section class="content" ng-app="manageApp">
<div growl></div>
<div class="row" ng-controller="customerManageController">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Customers Information</h3>
</div>
<div class="box-body">
<table class="table table-striped table-bordered" id="customer_table" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mobile</th>
<th>City</th>
<th>Email</th>
<th>Address1</th>
<th>Address2</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mobile</th>
<th>City</th>
<th>Email</th>
<th>Address1</th>
<th>Address2</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
//js file
var manageApp = angular.module('manageApp', ['ngRoute', 'angular-growl', 'ngAnimate']);
manageApp.controller('customerManageController', function ($scope, $http, growl) {
$http({
method: 'POST',
url: 'list_customers',
headers: {
"Content-Type": "application/json"
},
}).success(function (data) {
for(var i=0; i<data.length; i++) {
var tableBody = tableBody+('<tr id="'+data[i].id+'"><td>'+data[i].id+'</td><td>'+data[i].name+'</td><td>'+data[i].mobile+'</td><td>'+data[i].city+'</td><td>'+data[i].email+'</td><td>'+data[i].address1+'</td><td>'+data[i].address2+'</td><td><button ng-click="deleteFunc()" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i></button></td></tr>');
}
$('#tableBody').html(tableBody);
$('#customer_table').DataTable();
});
$scope.deleteFunc = function () {
alert('here');
}
});
The problem is you're inserting new HTML that won't be bound to the controller. Anytime you insert new HTML code with Angular directives that isn't compiled, like you did with JQuery, it won't be bound to the controller unless you use the $compile function to bind it.
There is a way you can do this with your code but instead this should be refactored. You're waiting for data from a POST request before you render it. Instead of binding the HTML after you get the data (this is where $compile would be required) you can instead make use of a $scope which will contain an array of the data and render the HTML based on what is in that array.
The code would look like this:
<section class="content" ng-app="manageApp">
<div growl></div>
<div class="row" ng-controller="customerManageController">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Customers Information</h3>
</div>
<div class="box-body">
<table class="table table-striped table-bordered" id="customer_table" >
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mobile</th>
<th>City</th>
<th>Email</th>
<th>Address1</th>
<th>Address2</th>
<th>Action</th>
</tr>
</thead>
<!-- Table now populates with data after it's received -->
<tbody id="tableBody">
<div ng-repeat="for data in receivedData">
<tr id="{{ data.id }}>
<td>{{data.id}}</td>
<td>{{data.name}}</td>
<td>{{data.mobile}}</td>
<td>{{data.city}}</td>
<td>{{data.email}}</td>
<td>{{data.address1}}</td>
<td>{{data.address2}}</td>
<td>
<button ng-click="deleteFunc()" class="btn btn-danger">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
</td>
</tr>
</div>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Name</th>
<th>Mobile</th>
<th>City</th>
<th>Email</th>
<th>Address1</th>
<th>Address2</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
JavaScript:
var manageApp = angular.module('manageApp', ['ngRoute', 'angular-growl', 'ngAnimate']);
manageApp.controller('customerManageController', function ($scope, $http, growl) {
// This will hold the data
$scope.receivedData = [];
$http({
method: 'POST',
url: 'list_customers',
headers: {
"Content-Type": "application/json"
},
}).success(function (data) {
// If here there is data, show it.
if (data.length > 0) {
$scope.receivedData = data;
}
}
});
$scope.deleteFunc = function () {
alert('here');
}
});

Yajra Datatable get name by id laravel 5.3

Here's my car index blade code :
#extends('layout.master')
#section('content')
<div id="content" class="content">
<h1 class="page-header">Car <small>panel</small></h1>
#include('partials.message')
<div class="row">
<div class="col-md-12">
<div class="panel panel-inverse" data-sortable-id="ui-general-1">
<div class="panel-heading">
<div class="panel-heading-btn">
<i class="fa fa-plus"></i> Add
</div>
<h4 class="panel-title">Car</h4>
</div>
<div class="panel-body">
<table class="table table-bordered" id="datatable" style="width: 100%">
<thead>
<tr>
<th>Car Category</th>
<th>Year</th>
<th>Color</th>
<th>Plate No</th>
<th>Status</th>
<th>Action</th>
</tr>
<tr id="filterRow" class="hidden-xs">
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<i class="fa fa-angle-up"></i>
</div>
#include('partials.modalDelete')
</div>
#endsection
#push('pageRelatedJs')
<script type="text/javascript">
$(document).ready(function(){
var datatable = $('#datatable').DataTable(
{
dom: "lfrtip",
responsive: true,
processing: true,
serverSide: true,
ajax: {
url: "{{ route('car.list') }}",
data: { '_token' : '{{csrf_token() }}'},
type: 'POST',
},
columns: [
{ data: 'car_category_id', name: 'car_category_id', className: 'text-center',},
{ data: 'year', name: 'year', className: 'text-center', },
{ data: 'color', name: 'color', className: 'text-center', },
{ data: 'plate_no', name: 'plate_no', className: 'text-center', },
{ data: 'status', name: 'status', className: 'text-center', },
{ data: 'action', name: 'action', className: 'text-center', orderable: false, searchable: false },
],
initComplete: function () {
this.api().columns().every(function () {
$('#datatable thead tr#filterRow th:not(:last-child)').each( function () {
var title = $('#datatable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" class="col-md-12" placeholder="Search by '+title+'" />');
});
$("#datatable thead input").on('keyup change', function () {
datatable.column( $(this).parent().index()).search(this.value).draw();
});
});
}
});
});
</script>
<script src="{{ asset('assets/js/modal_delete.js') }}"></script>
#endpush
How can I get the car_category [name] by Id.
Note: 2 tables car_category and car
Ex: I have 2 categories, 1.suv 2.sport. and I want to add a new car, when I submit it, it shows id instead of name. any idea ?

Categories