Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 996 of 2109
How to alias a table in Laravel Eloquent queries using Query Builder?
Laravel Eloquent provides several ways to alias tables in database queries, making your code more readable and enabling complex joins. Table aliases are particularly useful when working with multiple tables or when you need to shorten long table names. Sample Data Let's assume we have a students table with the following data − +----+---------------+------------------+-----------------------------+-----------------------------+---------+------+ | id | name | email | created_at ...
Read MoreC program to write an image in PGM format
The PGM (Portable Gray Map) format is part of the Netpbm package that provides an easy way to store 2D arrays as grayscale images. Unlike complex formats like PNG or JPEG, PGM files use a simple ASCII format that makes them easy to create and read programmatically. Each PGM file starts with a magic number P2 (for ASCII encoding) followed by dimensions, maximum gray value, and pixel data. The format is human-readable and portable across different platforms. Syntax P2 width height max_gray_value pixel_values... PGM File Structure To write a PGM file, follow these ...
Read MoreHow to access the public directory in Laravel?
In Laravel, you can access files in the public directory using the File facade or PHP's built−in functions. The public directory is where Laravel stores assets like images, CSS, and JavaScript files that need to be directly accessible via web URLs. Make sure to import the File facade in your controller: use Illuminate\Support\Facades\File; Laravel Public Directory Structure public/ images/ css/ ...
Read MoreC Program to validate an IP address
In this program we will see how to validate an IP address using C. The IPv4 addresses are represented in dot-decimal notation. There are four decimal numbers (all are ranging from 0 to 255). These four numbers are separated by three dots. An example of a valid IP is: 192.168.4.1 Syntax int validate_ip(char *ip); Validation Steps To validate the IP address we should follow these steps − Tokenize the string (IP address) using the dot "." delimiter If the sub strings are containing ...
Read MoreHow to Use OrderBy for Multiple Columns in Laravel?
In Laravel, you can sort query results by multiple columns using the orderBy() method chained together. This allows you to create complex sorting logic where records are first sorted by one column, then by another column for records with identical values in the first column. Syntax The basic syntax for ordering by multiple columns in Laravel is − Model::orderBy('column1', 'ASC/DESC') ->orderBy('column2', 'ASC/DESC') ->get(); Note: To run the examples below, ensure you have Laravel installed with a configured database connection and a Student model ...
Read MoreC program to print characters without using format specifiers
In this article we will see how we can print some characters without using any kind of format specifiers. The format specifiers in C are %d, %f, %c etc. These are used to print characters and numbers in C using the printf() function. Here we will see another way to print characters without using %c format specifier. This can be done by putting ASCII values directly in hexadecimal form using escape sequences. Syntax printf("\xHH"); // HH is hexadecimal ASCII value Method 1: Using Hexadecimal Escape Sequences The \x escape sequence allows us ...
Read MoreWrite a C program that does not terminate when Ctrl+C is pressed
In C, we can create a program that does not terminate when Ctrl+C is pressed by using signal handling. The Ctrl+C key combination generates the SIGINT (Signal Interrupt) signal, which normally terminates a running process. However, we can intercept this signal using the signal() function and define custom behavior instead. Syntax #include void (*signal(int sig, void (*func)(int)))(int); Where sig is the signal number and func is the handler function to be called when the signal is received. Common Signal Types Signal Description SIGABRT Indicates Abnormal ...
Read MoreWhat is Fillable Attribute in a Laravel model?
The fillable attribute in Laravel models is a security feature that defines which database fields can be safely mass−assigned. It protects against mass assignment vulnerabilities by explicitly specifying which fields can be updated through methods like create() or update(). What is Mass Assignment? Mass assignment occurs when you pass an array of data directly to model methods. Without proper protection, malicious users could potentially modify unintended fields by adding extra parameters to HTTP requests. Setting Up Fillable Attributes First, create a model using Artisan command ? Run the following command to create a Student ...
Read MoreHow to validate an array in Laravel?
In Laravel, you can validate array data using the built−in Validator class. This is essential for ensuring data integrity before processing user input or form submissions. To use Laravel's validation features, ensure you have Laravel installed and include the Validator facade in your controller. use Illuminate\Support\Facades\Validator; Validating Associative Arrays When working with associative arrays, you define validation rules for each key. Here's how to validate an array with firstname, lastname, and address fields ? Array Validation is Successful Missing Required Fields If a ...
Read MoreWhy array index starts from zero in C/C++ ?
An array arr[i] is interpreted as *(arr+i). Here, arr denotes the address of the first array element or the 0th index element. So *(arr+i) means the element is at i distance from the first element of the array. Therefore, array index starts from 0 as initially i is 0 which means the first element of the array. In this article, we will see examples of C code to understand the reason why an array starts from index 0. Syntax data_type array_name[array_size]; // Accessing element: array_name[index] where index starts from 0 Why Array Index Starts ...
Read More