07 September, 2020
<?php
Route:
Route::get('/cuisines','backEnd\contentManagement\CuisinesController@index');
Route::post('/data/cuisines','backEnd\contentManagement\
CuisinesController@cuisinesList');
Route::match(['get','post'],'/cuisine/add','backEnd\contentManagement\
CuisinesController@add');
Route::match(['get','post'],'/cuisine/edit/{cuisine_id}','backEnd\
contentManagement\CuisinesController@edit');
//soft-delete of cusisine
Route::match(['get','post'],'/cuisine/delete/{cuisine_id}','backEnd\
contentManagement\CuisinesController@delete');
?>
<!-- Controller -->
<?php
namespace App\Http\Controllers\backEnd\contentManagement;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth, Hash;
use App\Cuisine;
class CuisinesController extends Controller
{
public function index()
{
$page = 'cuisines';
return view('backEnd.contentManagement.cuisines.index', compact('page'));
}
public function cuisinesList(){
$draw = @$_POST['draw'];
$row = @$_POST['start'];
$rowperpage = @$_POST['length']; // Rows display per page
$columnIndex = @$_POST['order'][0]['column']; // Column index
$columnName = @$_POST['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = @$_POST['order'][0]['dir']; // asc or desc
$searchValue = @$_POST['search']['value']; // Search value
$listing = Cuisine::select('*')
->whereNull('deleted_at')
->skip($_POST['start'])
->take($_POST['length']);
$listing = $listing->orderBy($columnName,$columnSortOrder);
$recordCount = Cuisine::whereNull('deleted_at')
->count();
$with_filter_count = $listing->count();
// ----- search
if($searchValue != ''){
$listing = $listing->where('name','like','%'.$searchValue.'%');
$with_filter_count = $listing->count();
}
if($with_filter_count == 0){
$with_filter_count = $recordCount;
}
$allRecords = $listing->get()->toArray();
// Total number of records without filtering
$totalRecords = $recordCount;
//Total number of record with filtering
$totalRecordwithFilter = $with_filter_count;
$data = array();
foreach ($allRecords as $key => $value) {
$joined_on = date('d M, Y', strtotime($value['created_at']));
$encoded_id = $value['id'];
// $encoded_id = base64_encode($value['id']);
$action = '<a href="'.url('/admin/cuisine/edit/'.$encoded_id).
'" title="Edit"><i class="fa fa-edit"></i>
</a>
<a href="'.url('/admin/cuisine/delete/'.$encoded_id).'"
title="Send Credential"><i class="fas fa-trash-alt"></i>
</a>';
$data[] = array(
"name"=>ucfirst($value['name']),
"action"=>$action,
);
}
$response = array(
"draw" => intval($draw),
"iTotalRecords" => $totalRecords,
"iTotalDisplayRecords" => $totalRecordwithFilter,
"aaData" => $data
);
echo json_encode($response);
}
public function add(Request $request){
if($request->isMethod('post')){
$data = $request->all();
//$id = $this->route('post');
$validatedData = $request->validate
([
'name'=>'required|max:20|min:3',
]);
$cusisineData = new Cuisine;
$cusisineData->name = $data['name'];
if($cusisineData->save())
{
return redirect('/admin/cuisines')->with
('success','Cuisine added successfully');
}
else
{
return redirect('/admin/cuisines')
->with('errors',COMMON_ERROR);
}
}
$page = 'cuisines';
return view('backEnd.contentManagement.cuisines.form',
compact('page'));
}
public function edit(Request $request,$cuisine_id)
{
$cuisine_detail = Cuisine::where('id',$cuisine_id)->first();
if ($request->isMethod('post')){
$data = $request->all();
$this->validate($request,[
'name'=>'required|max:20|min:3',
]);
$cuisine_detail->name = $data['name'];
if ($cuisine_detail->save()) {
return redirect('/admin/cuisines')->with('success',
'Cuisine Updated Successfully');
}else{
return redirect()->back()->with('errors',COMMON_ERROR);
}
}
$page = 'cuisines';
return view('backEnd.contentManagement.cuisines.form',
compact('page','cuisine_detail','cuisine_id'));
}
public function delete($cuisine_id)
{
$del = Cuisine::where('id',$cuisine_id)->update(['deleted_at'=>
date('Y-m-d h:i:s')]);
if ($del)
{
return redirect()->back()->with('success',
'Cuisine deleted successfully');
}
else
{
return redirect()->back()->with('errors',COMMON_ERROR);
}
}
}
// Blade File: index. thats is not main file it is only view file ;
// Index.blade.php
<?php
@extends('backEnd.layouts.master')
@section('title','categories')
@section('content')
<div class="page-wrapper">
<div class="page-breadcrumb">
<div class="row">
<div class="col-12 d-flex no-block align-items-center">
<h4 class="page-title">Content Management </h4>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<h5 class="card-title">Categories</h5>
<div class="new_add_btn d-flex justify-content-end
align-items-center mb-4">
<a href="{{ url('admin/category/add') }}"
class="btn btn-primary mr-1">Add New</a>
</div>
<div class="table-responsive">
<table id="zero_config2"
class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
@include('backEnd.common.footer')
</div>
@endsection
@section('scripts')
<script>
$('#zero_config2').DataTable({
"order": [[ 0, "desc" ]],
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax':{
'url': "{{ url('admin/data/categories') }}",
"error": function(reason) {
console.log(reason);
}
},
"columns" : [
{ data: 'name' },
{ data: 'image' },
{ data: 'action', name: 'action', orderable: false, searchable: false}
]
});
</script>
@endsection
form.blade.php
Note: this is main file you can edit and update only one file;
<?php
if(isset($categorieData)){
$title = 'Edit';
$form_id = 'CategoryForm';
$image_text = 'Update Image';
$action = url('/admin/category/edit/'.$category_id);
}else{
$title = 'Add';
$form_id = 'CategoryForm';
$image_text = 'Update Image';
$action = url('/admin/category/add');
}
?>
@extends('backEnd.layouts.master')
@section('title',$title.' Content Management')
@section('content')
<div class="page-wrapper">
<div class="page-breadcrumb">
<div class="row">
<div class="col-12 d-flex no-block align-items-center">
<h4 class="page-title">Content Management</h4>
<div class="ml-auto text-left">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{{ url('admin/categories') }}">Content</a></li>
<li class="breadcrumb-item active" aria-current="page">
{{ $title }} category</li>
</ol>
</nav>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<form class="form-horizontal" name="registration" method="post"
action="{{ $action }}"
id="user_form" enctype="multipart/form-data">
@csrf
<div class="card-body">
<h4 class="card-title">{{ $title }} Category</h4>
<div class="form-group row">
<label class="col-sm-3 text-right control-label
col-form-label">Name:</label>
<div class="col-sm-7">
<input type="text" class="form-control"
placeholder="Name" name="name"
value="{{ isset($categorieData['name'])?
$categorieData['name']: old('name') }}">
</div>
</div>
<label for="image" class="m-t-10"></label>
<?php
$image = DefaultImgPath;
if(!empty($categorieData['image'])){
$image =
ContentCategoriesImgPath.'/'.$categorieData['image'];
}
?>
<div class="container-fluid"
style="padding-left: 270px; padding-bottom: 20px;">
<div>
<img src="{{$image}}" id="old_image"
alt="No image" class="img-fluid" width="15%"
height="10%" accept=".jpg,.png,.gif,.jpeg">
</div>
<div>
<div class="Upload-img mt-3">
<span class="uploader">
<button type="button"
class="btn btn-danger">{{ $image_text }}</button>
<input type="file" name="image"
id="img_upload" class="img_cls">
// <!-- <span class="img_load">
// <input type="hidden"
name="image" id="img_upload" class="img_cls">
// </span> -->
</span>
</div>
</div>
</div>
</div>
@if($errors->any())
<div class="form-group row">
<label class="col-sm-3 text-right control-label
col-form-label"></label>
<div class="col-sm-7">
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
</div>
@endif
<div class="error">
</div>
<div class="border-top">
<div class="card-body">
@csrf()
<button type="submit" class="btn btn-primary"
style="float: right; margin-bottom: 20px">
Submit</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@include('backEnd.common.footer')
</div>
@endsection
?>
Regex pattern validation in laravel
Programing Coderfunda
September 07, 2020
No comments
'name' => ['required', 'regex:^[A- ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa- zàâçéèêëîïôûùüÿñæœ0-9_.,()]+$^ ']
'name' => ['required', 'regex:/^[A- ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa- zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/']
address:{
minlength:2,
maxlength:500,
regex:/^[a-zA-z,-/_=. #]+$/,
},
protected static $rules = [
'zip_code' => 'required|regex:/\b\d{5}\b/'
];Xampp Server Start
Programing Coderfunda
September 07, 2020
No comments
Regex pattern validation in laravel
Programing Coderfunda
September 07, 2020
No comments
'name' => ['required', 'regex:^[A- ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa- zàâçéèêëîïôûùüÿñæœ0-9_.,()]+$^ ']
'name' => ['required', 'regex:/^[A- ZÀÂÇÉÈÊËÎÏÔÛÙÜŸÑÆŒa- zàâçéèêëîïôûùüÿñæœ0-9_.,() ]+$/']
address:{
minlength:2,
maxlength:500,
regex:/^[a-zA-z,-/_=. #]+$/,
},
protected static $rules = [
'zip_code' => 'required|regex:/\b\d{5}\b/'
];
Xampp Server Start
Programing Coderfunda
September 07, 2020
No comments
Laravel validate decimal 0-99.99
Programing Coderfunda
September 07, 2020
No comments
Laravel validate decimal 0-99.99
The Laravel
2nd...................
Arrrgh! Don't listen to the regular expression answers. RegEx is icky for this, and I'm not talking just performance. It's so easy to make subtle, impossible to spot mistakes with your regular expression.
If you can't use
The
The check on the length is for a special case involving empty strings. Also note that it falls down on your 0x89f test, but that's because in many environments that's an okay way to define a number literal. If you want to catch that specific scenario you could add an additional check. Even better, if that's your reason for not using
The Laravel
between validation rule is actually pretty powerful and can handle decimal values as well. So there's no need to use regex just do this:'required|between:0,99.99'
function rules(){
return [
'field_name'=> array('regex:/^(?:d*.d{1,2}|d+ )$/','min:1','max:10')
];
}
Validate decimal numbers in JavaScript - IsNumeric()
// Whitespace strings:
IsNumeric(' ') == true;
IsNumeric('\t\t') == true;
IsNumeric('\n\r') == true;
// Number literals:
IsNumeric(-1) == false;
IsNumeric(0) == false;
IsNumeric(1.1) == false;
IsNumeric(8e5) == false;Some time ago I had to implement an IsNumeric function, to find out if a variable contained a numeric value, regardless of its type, it could be a String containing a numeric value (I had to consider also exponential notation, etc.), a Number object, virtually anything could be passed to that function, I couldn't make any type assumptions, taking care of type coercion (eg. +true == 1; but true shouldn't be considered as "numeric").2nd...................
Arrrgh! Don't listen to the regular expression answers. RegEx is icky for this, and I'm not talking just performance. It's so easy to make subtle, impossible to spot mistakes with your regular expression.
If you can't use
isNaN(), this should work much better:function IsNumeric(input)
{
return (input - 0) == input && (''+input).trim().length > 0;
}Here's how it works:The
(input - 0) expression forces JavaScript to do type coercion on your input value; it must first be interpreted as a number for the subtraction operation. If that conversion to a number fails, the expression will result in NaN. This numeric result is then compared to the original value you passed in. Since the left hand side is now numeric, type coercion is again used. Now that the input from both sides was coerced to the same type from the same original value, you would think they should always be the same (always true). However, there's a special rule that says NaN is never equal to NaN, and so a value that can't be converted to a number (and only values that cannot be converted to numbers) will result in false. The check on the length is for a special case involving empty strings. Also note that it falls down on your 0x89f test, but that's because in many environments that's an okay way to define a number literal. If you want to catch that specific scenario you could add an additional check. Even better, if that's your reason for not using
isNaN() then just wrap your own function around isNaN() that can also do the additional check.Laravel set between digits in validation
'required|integer|digits_ between:1,10'
or'display_post_count' => 'required|min:1|max:10',Get Multipal Array Data Array in Array Laravel
Programing Coderfunda
September 07, 2020
Laravel
No comments
Array
(
[0] => Array
(
[id] => 8
[restaurant_id] => 5
[category_id] => 1
[deleted_at] =>
[created_at] => 2020-08-31T08:40:58.000000Z
[updated_at] => 2020-08-31T08:40:58.000000Z
[categorylistdd] => Array
(
[id] => 1
[name] => Burger
[image] => Burger.svg
[banner] =>
[deleted_at] =>
[created_at] =>
[updated_at] =>
)
)
[1] => Array
(
[id] => 9
[restaurant_id] => 5
[category_id] => 2
[deleted_at] =>
[created_at] => 2020-08-31T08:44:40.000000Z
[updated_at] => 2020-08-31T08:44:40.000000Z
[categorylistdd] => Array
(
[id] => 2
[name] => Desert
[image] => Dessert.svg
[banner] =>
[deleted_at] =>
[created_at] =>
[updated_at] =>
)
(
[0] => Array
(
[id] => 8
[restaurant_id] => 5
[category_id] => 1
[deleted_at] =>
[created_at] => 2020-08-31T08:40:58.000000Z
[updated_at] => 2020-08-31T08:40:58.000000Z
[categorylistdd] => Array
(
[id] => 1
[name] => Burger
[image] => Burger.svg
[banner] =>
[deleted_at] =>
[created_at] =>
[updated_at] =>
)
)
[1] => Array
(
[id] => 9
[restaurant_id] => 5
[category_id] => 2
[deleted_at] =>
[created_at] => 2020-08-31T08:44:40.000000Z
[updated_at] => 2020-08-31T08:44:40.000000Z
[categorylistdd] => Array
(
[id] => 2
[name] => Desert
[image] => Dessert.svg
[banner] =>
[deleted_at] =>
[created_at] =>
[updated_at] =>
)
)
Answer : $value['categorylistdd'][' name'],
you can use Also pluck in laravel
Note: by use get->()->plucke(' Desert ')->addArray();
You will get all data of Name, Image , banner check top On
Laravel validate decimal 0-99.99
Programing Coderfunda
September 07, 2020
No comments
Laravel validate decimal 0-99.99
The Laravel
2nd...................
Arrrgh! Don't listen to the regular expression answers. RegEx is icky for this, and I'm not talking just performance. It's so easy to make subtle, impossible to spot mistakes with your regular expression.
If you can't use
The
The check on the length is for a special case involving empty strings. Also note that it falls down on your 0x89f test, but that's because in many environments that's an okay way to define a number literal. If you want to catch that specific scenario you could add an additional check. Even better, if that's your reason for not using
The Laravel
between validation rule is actually pretty
powerful and can handle decimal values as well. So there's no need to
use regex just do this:'required|between:0,99.99'
function rules(){
return [
'field_name'=> array('regex:/^(?:d*.d{1,2}|d+ )$/','min:1','max:10')
];
}
Validate decimal numbers in JavaScript - IsNumeric()
// Whitespace strings:
IsNumeric(' ') == true;
IsNumeric('\t\t') == true;
IsNumeric('\n\r') == true;
// Number literals:
IsNumeric(-1) == false;
IsNumeric(0) == false;
IsNumeric(1.1) == false;
IsNumeric(8e5) == false;
Some time ago I had to implement an IsNumeric function, to find out if a variable contained a numeric value, regardless of its type, it could be a String containing a numeric value (I had to consider also exponential notation, etc.), a Number
object, virtually anything could be passed to that function, I couldn't
make any type assumptions, taking care of type coercion (eg. +true == 1; but true shouldn't be considered as "numeric").2nd...................
Arrrgh! Don't listen to the regular expression answers. RegEx is icky for this, and I'm not talking just performance. It's so easy to make subtle, impossible to spot mistakes with your regular expression.
If you can't use
isNaN(), this should work much better:function IsNumeric(input)
{
return (input - 0) == input && (''+input).trim().length > 0;
}
Here's how it works:The
(input - 0) expression forces JavaScript to do type
coercion on your input value; it must first be interpreted as a number
for the subtraction operation. If that conversion to a number fails,
the expression will result in NaN. This numeric
result is then compared to the original value you passed in. Since the
left hand side is now numeric, type coercion is again used. Now that
the input from both sides was coerced to the same type from the same
original value, you would think they should always be the same (always
true). However, there's a special rule that says NaN is never equal to NaN,
and so a value that can't be converted to a number (and only values
that cannot be converted to numbers) will result in false. The check on the length is for a special case involving empty strings. Also note that it falls down on your 0x89f test, but that's because in many environments that's an okay way to define a number literal. If you want to catch that specific scenario you could add an additional check. Even better, if that's your reason for not using
isNaN() then just wrap your own function around isNaN() that can also do the additional check.Laravel set between digits in validation
'required|integer|digits_ between:1,10'
or'display_post_count' => 'required|min:1|max:10',