language value print in Laravel blade

<?php

// resources/lang/en/messages.php

return [
    'welcome' => 'Welcome to our application!',
];
echo __('messages.welcome');
{{ __('messages.welcome') }}

@lang('messages.welcome')

Laravel language file contains array



<?php

// resources/lang/en/messages.php

return [
  'month'=>array("जनवरी","फरवरी","मार्च","अप्रैल","मई","जून","जुलाई","अगस्त","सितम्बर","अक्टूबर","नवम्बर","दिसम्बर"),
];

{{ __('message.month.1') }}

two table column display in single query Laravel 8 | nested query in Laravel

Joins in Laravel

Inner Join Clause

The query builder may also be used to add join clauses to your queries. To perform a basic “inner join”, you may use the join method on a query builder instance. The first argument passed to the join method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. You may even join multiple tables in a single query:

use Illuminate\Support\Facades\DB;

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();

Left Join / Right Join Clause

If you would like to perform a “left join” or “right join” instead of an “inner join”, use the leftJoin or rightJoin methods. These methods have the same signature as the join method:

$users = DB::table('users')
            ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();

$users = DB::table('users')
            ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();

Cross Join Clause

You may use the crossJoin method to perform a “cross join”. Cross joins generate a cartesian product between the first table and the joined table:

$sizes = DB::table('sizes')
            ->crossJoin('colors')
            ->get();

Advanced Join Clauses

You may also specify more advanced join clauses. To get started, pass a closure as the second argument to the join method. The closure will receive a Illuminate\Database\Query\JoinClause instance which allows you to specify constraints on the “join” clause:

DB::table('users')
        ->join('contacts', function ($join) {
            $join->on('users.id', '=', 'contacts.user_id')->orOn(...);
        })
        ->get();

If you would like to use a “where” clause on your joins, you may use the where and orWhere methods provided by the JoinClause instance. Instead of comparing two columns, these methods will compare the column against a value:

DB::table('users')
        ->join('contacts', function ($join) {
            $join->on('users.id', '=', 'contacts.user_id')
                 ->where('contacts.user_id', '>', 5);
        })
        ->get();

Subquery Joins

You may use the joinSubleftJoinSub, and rightJoinSub methods to join a query to a subquery. Each of these methods receives three arguments: the subquery, its table alias, and a closure that defines the related columns. In this example, we will retrieve a collection of users where each user record also contains the created_at timestamp of the user’s most recently published blog post:

$latestPosts = DB::table('posts')
                   ->select('user_id', DB::raw('MAX(created_at) as last_post_created_at'))
                   ->where('is_published', true)
                   ->groupBy('user_id');

$users = DB::table('users')
        ->joinSub($latestPosts, 'latest_posts', function ($join) {
            $join->on('users.id', '=', 'latest_posts.user_id');
        })->get();

optional argument in Laravel route

Occasionally you may need to specify a route parameter that may not always be present in the URI. You may do so by placing a ? mark after the parameter name. Make sure to give the route’s corresponding variable a default value:

Route::get('/user/{name?}', function ($name = null) {
    return $name;
});

Route::get('/user/{name?}', function ($name = 'John') {
    return $name;
});

synchronous get request JavaScript

How to make a synchronous GET request in JavaScript?

<script>
localStorage.language="calendar_main";
function SignName(sign_id,id){
  var form = new FormData();
  var settings = {
  "url": "/api/api-function/"+sign_id+"/"+localStorage.language+"",
  "method": "GET",
  "timeout": 0,
  "headers": {
    
  },
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form,
  "async": false,
};

$.get(settings).done(function (response) {
  const obj = JSON.parse(response);
  var sign=obj['data'];
  //console.log(data);
  for(i in sign)
  {
    $("#sign"+id).append(sign[i]['name']);

  }
  
});
}

$(document).ready(function(){
                $(document).ajaxSuccess(function(){
                   // console.log("AJAX request successfully completed.");
                });
                $(document).ajaxError(function (event, jqxhr, settings) {
                    console.log("AJAX error.");
                    if (settings.url == "") {
         
                    }
                });  
                
            });
      
</script>
use async: false in your data

group by with like in laravel 8

$results = User::select(\DB::raw('YEAR(date) as year, COUNT(id) as amount'))
    ->groupBy(\DB::raw('YEAR(date)'))
    ->get();

So, we’re using DB::raw() for all select statement, also repeating the same condition in groupBy(). Here’s the visual result for my dummy seeded data:

Here’s how you can find PAN Card Number Online

Lost your PAN card? Here’s how you can download instant e-PAN

Lost your PAN card? Here’s how you can download instant e-PAN

A Permanent Account Number (PAN) card is considered one of the most important financial documents for the citizens of India as it helps a person with filing their income tax return. The PAN card not only facilitates KYC but helps with many day-to-day services, such as opening a bank account, obtaining a debit or credit card, carrying out huge money-related transactions.

It is a 10-character alphanumeric identification number assigned to all tax-payers in India. But what happens if you end up misplacing or losing it?

PAN card holders can download an instant e-PAN or digital version of their PAN card using the online facility of the income tax department. The entire procedure is user-friendly and it just uses your Aadhaar number and hardly takes 10 minutes.

Steps to download instant e-PAN

Step 1: Visit the official website of Income Tax e-filing https://www.incometax.gov.in.

Step 2: Under the section “Our Services”, search for the option ‘Instant e-PAN’.

Step 3: If you have downloaded e-PAN earlier, click on the ‘Check Status/Download e-PAN’ option, but you need to click on the ‘Get new e-Pan’ option if you haven’t downloaded e-PAN in the past.

Step 4: You must choose as per your requirement from the given options and then click on continue.

Step 5: Now, the page will open asking you to enter your 12-digit Aadhaar number. So, enter your Aadhaar number in the input field.

Step 6: As soon as you enter your Aadhaar number, the page will display a declaration, you need to click on continue.

Step 7: Next, an OTP will be sent to your registered or Aadhar-linked mobile number.

Step 8: Then, enter the OTP you have received on your mobile in the given field.

Step 9: The page will now display all your details. After checking all the information carefully, enter your email address in the specified field.

Step 10: You will soon receive your e-PAN in your email inbox. You can also get your e-PAN printed.

Point to note: If you have your PAN number, you can also download your e-PAN from the websites of UTIITSL or TIN-NSDL, depending upon where your original PAN card was generated.

The digital version of the PAN card or e-PAN is equally valid and can be used in the place of the original PAN card.

source:indiatoday

Select and deselect multiple checkbox and store date into JavaScript set for unique value

<form method="post" action="/live-yearly" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="selectedLiveValue" id="selectedLiveValue" required>
<input type="submit" value="Live">
</form>
 <th><input type="checkbox" id="selectAll"></th>
  <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
  <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
  <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
  <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
<script>
 var  selectedIds = new Set();


$(document).ready(function() {
$("#selectAll").click(function(){

if(! $(this).prop("checked")) {
              $(".id").prop("checked", false);
              $("#selectedLiveValue").val("");
              selectedIds.clear();
          } else {
              $(".id").prop("checked", true);
              $('input[name="ids"]:checked').each(function() {  
   selectedIds.add(this.value);
   selectedIds.forEach(function(value) {
  $("#selectedLiveValue").val(value+","+$("#selectedLiveValue").val());
});
});
   }  
        //  console.log($('input[name="ids"]:checked').serialize());
});


});

$(".id").click(function(){
  $("#selectedLiveValue").val("");
  if( $(this).prop("checked")) {
    selectedIds.add($(this).val());
  }else{
    selectedIds.delete($(this).val());
  }

selectedIds.forEach(function(value) {
  $("#selectedLiveValue").val(value+","+$("#selectedLiveValue").val());
});

});


  </script>

javascript:void(0)

Usage of javascript:void(0) means that the author of the HTML is misusing the anchor element in place of the button element. Anchor tags are often abused with the onclick event to create pseudo-buttons by setting href to “#” or “javascript:void(0)” to prevent the page from refreshing.

Get value of selected checkbox jQuery

    <th><input type="checkbox" id="selectAll"></th>
     <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
     <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
     <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
     <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
     <td><input type="checkbox" class="id" value="{{ $d->id }}" name="ids" ></td>
$(document).ready(function() {
$("#selectAll").click(function(){

if( $(this).prop("checked")) {
              $(".id").prop("checked", false);
          } else {
              $(".id").prop("checked", true);
          }  

          console.log($('input[name="ids"]:checked').serialize());

//OR


          $('input[name="ids"]:checked').each(function() {
   console.log(this.value);
});

});
});

how to remove sorting option from datatables

 $(document).ready(function() {

    $('#example').DataTable( {
      "aoColumnDefs": [
          { 'bSortable': false, 'aTargets': [ 0 ] }
       ]
      
  });

});
 $(document).ready(function() {

    $('#example').DataTable( {
  
       "columnDefs": [
        { "orderable": false, "targets": [1] }
    ]
  });

});