Categories
Learning

How to calculate the costing of grams from per kg weight?

For the simple question here is the simple answer:

as we know 1kg = 1000 grams

Formular for easy getting grams rate from per kg is looks like:

So g grams is g/1000 kg and the price will be g/1000 * r (rupees/kg)
or
rupees/kg= g*r/1000

For example to calculate the rate of 100 grams from per kg.

Let say we have some wheat item whose rate is 1 kg = 20 rupees and we have to calculate the rate for 100 grams wheat?
100/1000 * 20 = 2 rupees
or
100 * 20/1000 = 2 rupees

Hope this solves our understanings.

Happy learning!

Categories
Learning

If its Laravel or a simple MYSQL a query/fetch of inner join table, return’s id of joined table, but you don’t want that, how to fix?

Hello,

First sorry for such long question in the heading. Will start with small story and then right to the solution fix I found.

Facing issue of getting id of Joined table in my current laravel project, where I need a Id column value from the Main table not the one which I used to inner join for the records to pull in.

Here is my existing query of Laravel returning t he id of customer table where I was looking id of Bill’s Table:

$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
                ->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
                ->orderBy('bills.id', 'desc')
                ->get(['bills.*','customers.*', ]);

So the right solution is at the last line in the above code, please carefully see the get() function array parameters; I switched them, so it finally returns the id values of bills not of customer table. (as customer table also id column which matches with bill’s table column)

$data = Bill::join('customers', 'customers.id', '=', 'bills.customer_id')
                ->where('bills.store_id', 'LIKE', '%'. $storeId . '%')
                ->orderBy('bills.id', 'desc')
                ->get(['customers.*', 'bills.*']);

This results be the records with bills id not customer’s id in laravel elqouent or mysql inner join.

Thanks for reading and learning.

Happy learning.

Categories
Learning

How we can write complex SCSS mixin with if else condition and null value passed or on no value passed?

Hello

Welcome, to this short post on writing/learning a little complex SCSS Mixin for your project/learning.

To keep it straight and short here it is the code example:

@mixin setWH($w: false, $h: false, $unit: false, $isImportant: false) {
   @if $w AND $unit AND $isImportant {
       width: unquote($w + $unit + ' !important');
   } @else if $w AND $isImportant {
       width: $w + ' !important';
   }
   @else if $w AND $unit {
       width: $w + $unit;
   } @else if $w {
       width: $w;
   }
 
   @if $h AND $unit AND $isImportant {
       height: unquote($h + $unit + ' !important');
   } @else if $h AND $isImportant {
       width: unquote($h + ' !important');
   } @else if $h AND $unit {
       height: $h + $unit;
   } @else if $h {
       height: $h;
   }
}

Usage Examples:


//Usage examples:
.myMixinTest1 {
  @include setWH(15, 5, 'em');
}

.myMixinTest2 {
  @include setWH(6, 4.3, "rem");
}

.myMixinTest3 {
  @include setWH(60, false, "px");
}

.myMixinTest4 {
  @include setWH(false, 30, "px");
}

.myMixinTest5 {
  @include setWH(27, 3, "rem", true);
}

It looks complex if you pay a little bit close look, its most simple.

You may extend more with if else or else conditions. I just kept to that extend as not require for me any else condition for error handling or something else to output.

A small ~codepen~ in action!

Hope you like & enjoyed learning!

Happy Learning!

Categories
Learning

Looking for 3D print in Miraroad, Mumbai, Thane?

Hello,

If you are looking for 3D print service and if you got the file and need a print, you can reach out here 3dprint@doableyo.com.

They respond usually on weekends for the delivery of print but you can write them anytime for any queries, they are new in 3D printing 👣🐾 but they can solve and helpful for the problem you might have.

3dprint.doableyo.com (the page will getting ready soon or might got ready)

Thanks for visiting!

Categories
Learning

How to call Laravel one Controller method into another?

Hello welcome to this post!

As of part of learning and development of laravel project I was simply looking syntax how to call laravel controller method in another controller.

Here is some tips and example:

Make sure you declared function as with public keyword while defining any method/function in controller.

Method updateMethod defined in controller called DoctorController.php as follow:

public function updateMethod($request, $id) {
// echo $id;
. . . // more lines of your code here
}

Secondly calling updateMethod in controller called DoctorApiController.php

public function updateDoctor(Request $request, $id) {
      if (Doctor::where('id', $id)->exists()) {
        $result = (new DoctorController)->updateMethod($request, $id);
        
        return response()->json([
            "message" => "Doctor updated successfully"
        ], 200);
        } else {
        return response()->json([
            "message" => "Doctor not found"
        ], 404);
        
    }
   }

If you got any error with DoctorController or your Controller class name not found or any such please add: use App\Http\Controllers\DoctorController; on top of the file.

This was the one way to simply call method of laravel one controller to other.

Hope it helpful. Thanks for visiting and reading.

Categories
Learning

WhatsApp, Facebook, Instagram go down

Hello Hi,

Lot of us facing currently down issue from Whatsapp, Facebook and Instagram:

Here are there tweets on issues:

Instagram

Facebook

Whatsapp

So we don’t need to worry much and relax our nerves and mind and let the giants work on the issue until than we can take some good good nap for living life’s.

Thanks for reading and visiting.

Categories
Learning

Looking for fulltime Sr Frontend Developer position

Hello, welcome here to this post.

Jatinder Singh is looking fulltime Sr Frontend Developer position remotely or at worldwide locaiton.

He have 8+ years of frontend development experience, his core expertise is into ReactJS, NextJs, Angular, NodeJs(30-40%), Javascript, ES6, HTML5, CSS3, Bootstrap, jQuery, GraphQL, ApolloClient and ApolloServer.

His recent work of https://sabziyaan.doableyo.com or https://sz.doableyo.com using NextJS, ReactJS, he have also worked on Ecommerce Project which will be soon launched.

He currently lives in Mumbai with his family.

He actively looking out for fulltime job, in open culture, no politics environment and always seek an opportunity to learn and grow.

He loves the quote of Richard Branson:

To reach out him, you may quickly drop a note at hello@tortoisefeel.com. The message will share instantly with them.

Thank your for reading and visiting the post.

Categories
Learning

What is the syntax or how to add AND with where clause in PHP MYSQL?

Hello, welcome to this short post or an answer for this question.

Here is example do use AND with WHERE clause in MYSQL statement in PHP or general writing of SQL Statement.

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)

This how we can use AND in where clause., similarly if we need OR in WHERE clause, we can use as below:

SELECT *
FROM orders
WHERE (userId = 111 AND orderId = 185)
OR (userId > 100);

Just if we are looking for complex query with multiple OR and AND in OR

SELECT orderId, orderNumber, orderStatus
FROM orders
WHERE (orderId = 185)
OR (orderNumber = 101 AND orderStatus = 'Cancelled')
OR (orderNumber = 102 AND orderStatus = 'InProgress' AND total >=500);

Purpose of this post to give you just syntax you might be looking for, but you know the logic how to implement it and use it!

Thanks for visiting and happy learning!

Categories
Learning

How to update in Laravel 8 all columns in database for form fields required and non required?

Hello, welcome to this question post.

I was looking for quick and succint turn around for this question and after searching lot on this one of post gave me any idea to update my rest of non-validate fields of form and also which don’t have validate rules at laravel model or controller level.

So here if my modified update() function from laravel Controller to update non required form fields or rules set in laravel controller or model, with in easy simple PHP style.

public function update(Request $request, $id)
    {
        
        $validatedData = $request->validate([
            'name' => 'required|max:255',
            'price' => 'required',
        ]);
        
        $nonRequiredFields = [
            'discount' => $request->discount,
            'qty' => $request->qty,
            'tax'=> $request->tax,
            'shipping' => $request->shipping,
            'handling' => $request->handling,
        ];
        
        Food::where('foodId', '=', $id)->update(array_merge($validatedData, $nonRequiredFields));
        
        return redirect()->route('food.index')->with('success', 'Food successfully updated');

}

In the code above I have given readable name to variable ($nonRequiredFields) which can be easily understand and I found this way the solution is working!

If you know more better approach kindly send me a not or if comments are open to this post please do comment.

Thanks for visiting and reading the post.

Categories
Learning

What to do when get nextjs server error when loading image from scss/sass variable in nextjs Image component?

Server Error
Error: Failed to parse src ""https://yourdomain.com/develop-app/assets/images/body-bg5.png"" on `next/image`, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)

I was facing this error recently on my nextjs project, I wanted to load the background Image path from SCSS variable into the NextJs Image components.

Before this error occurred, I was hunting on google for the answer and found it that how to import scss variables into react component, and I found we can import scss variable by declaring in scss file itself using :export directive of scss

//Example of exporting variable from scss file

$BODY_BG: "https://yourdomain.com/develop-app/assets/images/ka-body-bg.png";
$BODY_BG_OPT1: "https://yourdomain.com/develop-app/assets/images/ka-body-bg1.png";

:export {
    BODY_BG: $BODY_BG;
    BODY_BG_OPT1: $BODY_BG_OPT1;
}

and then can import easily into react component by installing node-sass npm package and then import the file of scss variable into react component like :


import backgroundVar from "../styles/background.module.scss";

//(note: I have used backgroundVar as my variable import name for all the scss variables exported from background.module.scss file)

and use it like this in your react state hook or directly in react component

const homeBodyBg = trimOutThis(backgroundVar.BODY_BG_OPT5 && backgroundVar.BODY_BG_OPT5, /"/g, '');

const [bgImage, setBgImage] = useState(homeBodyBg || '');

To fix the error of nextjs error of:

Error: Failed to parse src ""https://yourdomain.com/develop-app/assets/images/body-bg5.png"" on `next/image`, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)

I wrote small function to trim off the double quotes “” which we get from scss variable declaration for path, here is that function below and you may notice in above code, I am already trimming the double quotes with empty string and then it works like charm!

//Function to replace any string pass to an empty string or to be replaceable by something else

export const trimOutThis = (str, regx, replaceValue = "") => {
  if (!str.length || !regx) return '';


  return str.replace(regx, replaceValue);
}
//Function invoking example


const homeBodyBg = trimOutThis(backgroundVar.BODY_BG_OPT5 && backgroundVar.BODY_BG_OPT5, /"/g, '');


output without double quotes ” for NextJS image src

Hope this will help you in your search and solving issues.


Have nice day & Happy Learnings.

Thanks for visiting.