Friday, November 25, 2022

Micros Cal formula

 First number x second number + fourth number + sixth number.
Code is 123456
then
1 x 2 + 4 + 6 = 12

Livewire Authorization

 

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

 
class EditPost extends \Livewire\Component
{
use AuthorizesRequests;
 
public $post;
 
public function mount(Post $post)
{
$this->post = $post;
}
 
public function save()
{
$this->authorize('update', $this->post);
 
$this->post->update(['title' => $this->title]);
}
}

Saturday, November 12, 2022

Replacing line break before inserting to mysql

 

var input = document.getElementById("input").value;

if (!input)
{
// Null or undefined or bad input
alert("Invalid input");
}



// Replace line-breaks with "\n"
this.logData.description = input.replace(/(?:\r\n|\r|\n)/g, '\\n');

Saturday, October 15, 2022

mysql duplicate table database

 

CREATE TABLE new-database-name.new-table-name
AS
SELECT * FROM old-database.old-table-name;

Schedule/Auto Email sending from Laravel (Cron Job)


1) php artisan make:command AutoBirthDayWish

 

2) php artisan make:mail BirthDayWish

namespace App\Mail;

use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Mail\Mailable;

use Illuminate\Queue\SerializesModels;

class BirthDayWish extends Mailable

{

use Queueable, SerializesModels;

public $user;

/**

* Create a new message instance.

*

* @return void

*/

public function __construct($user)

{

$this->user = $user;

}

/**

* Build the message.

*

* @return $this

*/

public function build()

{

return $this->subject('Happy Birthday '. $this->user->name)

->view('emails.birthdayWish');

}

}

 

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use Mail;

use App\Mail\BirthDayWish;

use App\Models\User;

class AutoBirthDayWish extends Command

{

/**

* The name and signature of the console command.

*

* @var string

*/

protected $signature = 'auto:birthdaywith';

/**

* The console command description.

*

* @var string

*/

protected $description = 'Command description';

/**

* Execute the console command.

*

* @return int

*/

public function handle()

{

$users = User::whereMonth('birthdate', date('m'))

->whereDay('birthdate', date('d'))

->get();

if ($users->count() > 0) {

foreach ($users as $user) {

Mail::to($user)->send(new BirthDayWish($user));

}

}

return 0;

}

}

 

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;

use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel

{

/**

* Define the application's command schedule.

*

* @param \Illuminate\Console\Scheduling\Schedule $schedule

* @return void

*/

protected function schedule(Schedule $schedule)

{

$schedule->command('auto:birthdaywith')->daily();

}

/**

* Register the commands for the application.

*

* @return void

*/

protected function commands()

{

$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');

}

}

 

 

 

Friday, October 14, 2022

Laravel 9 Vue 3 installation with vue-router

1) install laravel

2) install laravel/ui

3) install Auth

4) install vue

npm install vue@next @vue/compiler-sfc vue-loader@next


npm install vue-router@4

npm install @vitejs/plugin-vue


vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
 
export default defineConfig({
    plugins: [
        laravel(['resources/js/app.js','resources/css/app.css']),
        vue({
            template: {
                transformAssetUrls: {
                    // The Vue plugin will re-write asset URLs, when referenced
                    // in Single File Components, to point to the Laravel web
                    // server. Setting this to `null` allows the Laravel plugin
                    // to instead re-write asset URLs to point to the Vite
                    // server instead.
                    base: null,
 
                    // The Vue plugin will parse absolute URLs and treat them
                    // as absolute paths to files on disk. Setting this to
                    // `false` will leave absolute URLs un-touched so they can
                    // reference assets in the public directory as expected.
                    includeAbsolute: false,
                },
            },
        }),
        
    ],
    resolve: {
        alias: {
          vue: 'vue/dist/vue.esm-bundler.js',
        },
    },
});


app.js

import './bootstrap';

import {createApp} from 'vue'
import * as VueRouter from 'vue-router'
import ExampleComponent from './components/home.vue'
import AboutComponent from './components/about.vue'
const routes = [
{path: '/home', component: ExampleComponent},
{path: '/about', component: AboutComponent},
]

const router = VueRouter.createRouter({
history: VueRouter.createWebHistory('/ilhdb4/public/'),
routes,
})
const app = createApp({})
app.use(router)
app.mount('#app')

Tuesday, October 11, 2022

One to one in Vue Component

 

Booking::with('user')
        ->where('date','>=', Carbon::today())
        ->get());

FPDF in Vue Component

 

                  axios({
                method:'post',
                url:'/api/reportFuel/' + this.form.id,
                responseType:'arraybuffer',
                data: this.report
                })
                .then(function(response) {
                    let blob = new Blob([response.data], { type:   'application/pdf' } );
                    let link = document.createElement('a');
                    link.href = window.URL.createObjectURL(blob);
                    link.download = 'Report.pdf';
                    link.click();
                });

Tuesday, October 4, 2022

Configuring an LVM Volume with an ext4

 

3.2. Configuring an LVM Volume with an ext4 File System

This use case requires that you create an LVM logical volume on storage that is shared between the nodes of the cluster.
The following procedure creates an LVM logical volume and then creates an ext4 file system on that volume. In this example, the shared partition /dev/sdb1 is used to store the LVM physical volume from which the LVM logical volume will be created.

Note

LVM volumes and the corresponding partitions and devices used by cluster nodes must be connected to the cluster nodes only.
Since the /dev/sdb1 partition is storage that is shared, you perform this procedure on one node only,
  1. Create an LVM physical volume on partition /dev/sdb1.
    [root@z1 ~]# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created
    
  2. Create the volume group my_vg that consists of the physical volume /dev/sdb1.
    [root@z1 ~]# vgcreate my_vg /dev/sdb1
      Volume group "my_vg" successfully created
    
  3. Create a logical volume using the volume group my_vg.
    [root@z1 ~]# lvcreate -L450 -n my_lv my_vg
      Rounding up size to full physical extent 452.00 MiB
      Logical volume "my_lv" created
    
    You can use the lvs command to display the logical volume.
    [root@z1 ~]# lvs
      LV      VG      Attr      LSize   Pool Origin Data%  Move Log Copy%  Convert
      my_lv   my_vg   -wi-a---- 452.00m
      ...
    
  4. Create an ext4 file system on the logical volume my_lv.
    [root@z1 ~]# mkfs.ext4 /dev/my_vg/my_lv
    mke2fs 1.42.7 (21-Jan-2013)
    Filesystem label=
    OS type: Linux

Date format change in vue component

 

  import moment from 'moment'

  methods: { 
      format_date(value){
         if (value) {
           return moment(String(value)).format('YYYYMMDD')
          }
      },
   },

Then:

format_date(date)

Sunday, September 25, 2022

Vue in Laravel9 with vite

 

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
 
export default defineConfig({
    plugins: [
        laravel(['resources/js/app.js','resources/css/app.css']),
        vue({
            template: {
                transformAssetUrls: {
                    // The Vue plugin will re-write asset URLs, when referenced
                    // in Single File Components, to point to the Laravel web
                    // server. Setting this to `null` allows the Laravel plugin
                    // to instead re-write asset URLs to point to the Vite
                    // server instead.
                    base: null,
 
                    // The Vue plugin will parse absolute URLs and treat them
                    // as absolute paths to files on disk. Setting this to
                    // `false` will leave absolute URLs un-touched so they can
                    // reference assets in the public directory as expected.
                    includeAbsolute: false,
                },
            },
        }),
       
    ],
    resolve: {
        alias: {
          vue: 'vue/dist/vue.esm-bundler.js',
        },
    },
});

Thursday, September 22, 2022

Remote Desktop issue between windows 10/11 to VM- Server 2012 R2

 

Create New Key 

1) CredSSP->Parameters -> Deword 32 bit ->AllowEncryptionOracle ->2 (decimal)

Enable gpedit.msc in Windows 11

 run as administrator command prompt

paste

FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~*.mum") DO (
DISM /Online /NoRestart /Add-Package:"%F"
)
FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~*.mum") DO (
DISM /Online /NoRestart /Add-Package:"%F"
)

Tuesday, September 20, 2022

Windows Cannot Connect To The Printer

 1) regedit

Computer\HKLM\System\currentControlSet\Control\Print -> create Dword-32 

RpcAuthnLevelPrivacyEnabled ->0


2) Restart Print Spooler service

Monday, September 19, 2022

Authentication for Vue 3, Laravel 9 with Sanctum

 1) Kernel.php -> uncomment
'api' => [
             \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,

 2) php artisan make:controller API/AuthController

 

<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Models\User;
use Illuminate\Support\Facades\Auth;


class AuthController extends Controller
{
    public function register(Request $request){
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password'=> 'required',
            'c_password'=>'required|same:password'
        ],[
            'email.required' => 'The User Email must be a valid email address.'
         ]);
        if($validator->fails()){
            $response = [
                'success' =>false,
                'message'=>$validator->errors()
            ];
            return response()->json($response,400);
        }
        $input = $request->all();
        $input['password'] = bcrypt($input['password']);
        $user = User::create($input);
       
        $success['token']= $user->createToken('MyApp')->plainTextToken;
        $success['name'] = $user->name;

        $response = [
            'success' =>true,
            'data'=>$success,
            'message' =>'User register successfully',
           
        ];
        return response()->json($response,200);


    }
    public function login(Request $request){
        if(Auth::attempt(['email'=>$request->email,'password'=>$request->password])){
            $user = Auth::user();
            $success['token']= $user->createToken('MyApp')->plainTextToken;
            $success['name'] = $user->name;

        $response = [
            'success' =>true,
            'data'=>$success,
            'message' =>'User login successfully',
           
        ];
            return response()->json($response,200);
        }else{
            $response = [
                'success' =>false,
                'message' =>'Unauthorised Access'
            ];
            return response()->json($response);
        }
    }
}

3) register.vue

<template>
    <h1>Register here</h1>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 mt-4">
                <p class="text-danger" v-for="error in errors" :key="error">
                    <span v-for="err in error" :key="err">{{ err }}</span>
                    </p>
                <form @submit.prevent="register" >
                    <div class="form-group">
                        <label for="name">Full Name</label>
                        <input type="text" class="form-control" v-model="form.name" >
                        <label for="username">Login Email</label>
                        <input type="text" class="form-control" v-model="form.email" >
                        <label for="password">Password</label>
                        <input type="password" class="form-control" v-model="form.password">
                        <label for="password">Confirm Password</label>
                        <input type="password" class="form-control" v-model="form.c_password">
                        <button type="submit" class="btn btn-primary mt-3">Submit</button>
                    </div>
                </form>

            </div>
   
        </div>
    </div>
</template>

<script>
    import axios from 'axios';
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router"
export default {
    setup () {
        const router = useRouter();
        let form = reactive({
            name: '',
            email: '',
            password: '',
            c_password: ''
        });
        let errors = ref([])
        const register = async()=>{
            await axios.post('/api/register',form).then(res=>{
                if(res.data.success){
                    localStorage.setItem('token',res.data.data.token)
                    router.push({name:'dashboard'})
                }
            }).catch(e=>{
                errors.value = e.response.data.message
            })
        }
        return{
            form,
            register,
            errors
        }
    }
}
</script>

4) App.js or Routes.js

require('./bootstrap');

import {createApp} from 'vue'
import * as VueRouter from 'vue-router'

import login from './components/login.vue'
import TaskComponent from './components/TaskComponent.vue'
import CCTVComponent from './components/CCTVComponent.vue'
import SubComponent from './components/SubscriptionComponent.vue'
import dashboard from './components/dashboard.vue'
import register from './components/register.vue'

const routes = [
    {path: '/', name:'login', component: login, meta:{requiresAuth:false }},
    {path: '/tasks', component: TaskComponent, meta:{requiresAuth:true }},
    {path: '/cameras', component: CCTVComponent, meta:{requiresAuth:true }},
    {path: '/subs', component: SubComponent, meta:{requiresAuth:true }},
    {path: '/dashboard', name: 'dashboard', component: dashboard, meta:{requiresAuth:true }},
    {path: '/register', name: 'register', component: register, meta:{requiresAuth:false }}
]

const router = VueRouter.createRouter({
    history: VueRouter.createWebHistory(),
    routes,
    linkActiveClass: "active",
    linkExactActiveClass: "exact-active",
})
window.url = ''
const app = createApp({})


router.beforeEach((to,from)=>{
    if(to.meta.requiresAuth && !localStorage.getItem('token') ){
        return { name:'login' }
    }
    if(to.meta.requiresAuth == false && localStorage.getItem('token') ){
        return { name:'dashboard' }
    }
})


app.use(router)

app.mount('#app')


5) Dashboard or Logout 

<template lang="">
    <div class="container">
        <h2>Dashboard :</h2>
        <button type="button" class="btn btn-dark mt-2" @click="logout">Logout</button>
    </div>
</template>
<script>
    import { useRouter } from "vue-router"
export default {
    setup(){
        const router = useRouter();
        function logout(){
            localStorage.removeItem('token');
            router.push({name:'login'})
        }
        return {
            logout
        }
    }
}
</script>
<style lang="">
   
</style>

In API.php add those route

Route::controller(AuthController::class)->group(function () {
    Route::post('login', 'login');
    Route::post('register', 'register');
    Route::post('logout', 'logout');
    Route::post('refresh', 'refresh');
    Route::get('me', 'me');

});


 

6) login.vue

<template>
    <h1>Login here</h1>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 mt-4">
                <p class="text-danger" v-if="error" >{{ error }}</p>
                <form @submit.prevent="login" >
                    <div class="form-group">
                       
                        <label for="username">Login Email</label>
                        <input type="email" class="form-control" v-model="form.email" >
                        <label for="password">Password</label>
                        <input type="password" class="form-control" v-model="form.password">
                        <button type="submit" class="btn btn-primary mt-3">Submit</button>
                    </div>
                </form>

            </div>
   
        </div>
    </div>
</template>

<script>
    import axios from 'axios';
import { reactive, ref } from 'vue'
import { useRouter } from "vue-router"
export default {
    setup () {
        const router = useRouter();
        let form = reactive({
            email: '',
            password: ''
        });
        let error = ref('')
        const login = async()=>{
            await axios.post('/api/login',form).then(res=>{
                if(res.data.success){
                    localStorage.setItem('token',res.data.data.token)
                    router.push({name:'dashboard'})
                }else{
                    error.value = res.data.message;
                }
            })
        }
        return{
            form,
            login,
            error
        }
    }
}
</script>