Showing posts with label @StudentTechMitra. Show all posts
Showing posts with label @StudentTechMitra. Show all posts

laravel task by paradioiso solutions


Task for Laravel Developer :

### Task 1: Database Interaction **Objective:** Assess their ability to work with Eloquent ORM and

database operations in Laravel.

**Task Description:** Provide a Laravel application with User and Post models. The candidate needs to

implement the following: 1. Define a relationship between User and Post (One-to-Many). 2. Create a

route to fetch a user's posts and return them as JSON. 3. Implement a method to create a new post for a

user via POST request.


### Task 2: Authentication and Middleware **Objective:** Evaluate their understanding of Laravel's

authentication system and middleware.

**Task Description:** 1. Create a login page with email and password fields. 2. Upon successful login,

redirect the user to a dashboard. 3. Ensure that only authenticated users can access the dashboard using

middleware.


### Task 3: Error Handling and Validation **Objective:** Assess their knowledge of Laravel's error

handling and validation.

**Task Description:** 1. Create a form to add a new post with fields: title and content. 2. Implement

server-side validation to ensure both fields are required and the title is a maximum of 100 characters. 3.

Display appropriate error messages if validation fails.


### Task 4: API Development **Objective:** Check their ability to build APIs in Laravel.

**Task Description:** 1. Create an API endpoint that returns a list of posts in JSON format. 2. Include

optional filters (like date range, author, etc.) for the posts. 3. Implement pagination for the API response.


### Task 5: Custom Middleware **Objective:** Evaluate their capability to create and implement

custom middleware.

**Task Description:** 1. Create a middleware that checks if the request IP is allowed. 2. Apply this

middleware to a specific route that displays sensitive user information.




Database Interaction **Objective:** Assess their ability to work with Eloquent ORM and

database operations in Laravel.

done 


create  user and post models

user and pos trelations 

create a route to fetch logined users posts 

create post via postman



**Task Description:** Provide a Laravel application with User and Post models. The candidate needs to

implement the following: 1. Define a relationship between User and Post (One-to-Many). 2. Create a

route to fetch a user's posts and return them as JSON. 3. Implement a method to create a new post for a

user via POST request.


### Task 2: Authentication and Middleware **Objective:** Evaluate their understanding of Laravel's

authentication system and middleware.

**Task Description:** 1. Create a login page with email and password fields. 2. Upon successful login,

redirect the user to a dashboard. 3. Ensure that only authenticated users can access the dashboard using

middleware.


done

login page with email an dpassword fields

after login redirect to dashboard

login userfs only can access dashboard


### Task 3: Error Handling and Validation **Objective:** Assess their knowledge of Laravel's error

handling and validation.

**Task Description:** 1. Create a form to add a new post with fields: title and content. 2. Implement

server-side validation to ensure both fields are required and the title is a maximum of 100 characters. 3.

Display appropriate error messages if validation fails.


done

create post

validation at backend

display mesasges 


### Task 4: API Development **Objective:** Check their ability to build APIs in Laravel.

**Task Description:** 1. Create an API endpoint that returns a list of posts in JSON format. 2. Include

optional filters (like date range, author, etc.) for the posts. 3. Implement pagination for the API response.



### Task 5: Custom Middleware **Objective:** Evaluate their capability to create and implement

custom middleware.

**Task Description:** 1. Create a middleware that checks if the request IP is allowed. 2. Apply this

middleware to a specific route that displays sensitive user information.



Provide a Laravel application with User and Post models done

The candidate needs to

implement the following: 1. Define a relationship between User and Post (One-to-Many). 2. Create a

route to fetch a user's posts and return them as JSON. 3. Implement a method to create a new post for a

user via POST request.


1. Define a relationship between User and Post (One-to-Many). done

user.php


public function posts()

    {

        return $this->hasMany(Post::class,'created_by','id');

    }


post.php


  public function user()

    {

        return $this->belongsTo(User::class,'created_by');

    }

127.0.0.1:8000/api/user


{

    "status": "success",

    "message": "Fetched Successfully",

    "data": {

        "current_page": 1,

        "data": [

            {

                "id": 2,

                "name": "svs",

                "email": "svs@gmail.com",

                "email_verified_at": null,

                "mobile": "9123456789",

                "created_at": "2024-04-16T16:24:43.000000Z",

                "updated_at": "2024-04-16T16:24:43.000000Z",

                "posts": [

                    {

                        "id": 2,

                        "account_type": "savings",

                        "name": "sd",

                        "description": "sdsd",

                        "formula": "sdsd",

                        "upi_id": "svs@gmail.com",

                        "created_by": 2,

                        "updated_by": null,

                        "created_at": "2024-04-16T16:24:57.000000Z",

                        "updated_at": "2024-04-16T16:24:57.000000Z"

                    }

                ]

            },

            {

                "id": 1,

                "name": "Admin",

                "email": "admin@gmail.com",

                "email_verified_at": null,

                "mobile": "9848022338",

                "created_at": "2024-04-16T16:15:50.000000Z",

                "updated_at": "2024-04-16T16:15:50.000000Z",

                "posts": [

                    {

                        "id": 1,

                        "account_type": "savings",

                        "name": "moldthefuture",

                        "description": "sdsds",

                        "formula": "sdsd",

                        "upi_id": "sdsds",

                        "created_by": 1,

                        "updated_by": null,

                        "created_at": "2024-04-16T16:19:52.000000Z",

                        "updated_at": "2024-04-16T16:19:52.000000Z"

                    }

                ]

            }

        ],

        "first_page_url": "http://127.0.0.1:8000/api/user?page=1",

        "from": 1,

        "last_page": 1,

        "last_page_url": "http://127.0.0.1:8000/api/user?page=1",

        "links": [

            {

                "url": null,

                "label": "« Previous",

                "active": false

            },

            {

                "url": "http://127.0.0.1:8000/api/user?page=1",

                "label": "1",

                "active": true

            },

            {

                "url": null,

                "label": "Next »",

                "active": false

            }

        ],

        "next_page_url": null,

        "path": "http://127.0.0.1:8000/api/user",

        "per_page": 10,

        "prev_page_url": null,

        "to": 2,

        "total": 2

    }

}


127.0.0.1:8000/api/user?user_id=1


{

    "status": "success",

    "message": "Fetched Successfully",

    "data": {

        "current_page": 1,

        "data": [

            {

                "id": 1,

                "name": "Admin",

                "email": "admin@gmail.com",

                "email_verified_at": null,

                "mobile": "9848022338",

                "created_at": "2024-04-16T16:15:50.000000Z",

                "updated_at": "2024-04-16T16:15:50.000000Z",

                "posts": [

                    {

                        "id": 1,

                        "account_type": "savings",

                        "name": "moldthefuture",

                        "description": "sdsds",

                        "formula": "sdsd",

                        "upi_id": "sdsds",

                        "created_by": 1,

                        "updated_by": null,

                        "created_at": "2024-04-16T16:19:52.000000Z",

                        "updated_at": "2024-04-16T16:19:52.000000Z"

                    }

                ]

            }

        ],

        "first_page_url": "http://127.0.0.1:8000/api/user?page=1",

        "from": 1,

        "last_page": 1,

        "last_page_url": "http://127.0.0.1:8000/api/user?page=1",

        "links": [

            {

                "url": null,

                "label": "« Previous",

                "active": false

            },

            {

                "url": "http://127.0.0.1:8000/api/user?page=1",

                "label": "1",

                "active": true

            },

            {

                "url": null,

                "label": "Next »",

                "active": false

            }

        ],

        "next_page_url": null,

        "path": "http://127.0.0.1:8000/api/user",

        "per_page": 10,

        "prev_page_url": null,

        "to": 1,

        "total": 1

    }

implement sorting without sort in php

task


task 1:<?php //Complete sorting functionality without using any inbuilt sorting related functions $arr = [50,20,35,15,45]; echo "Before Sorting <br/>"; print_r($arr); //sorting logic start //write your code here //sorting logic end echo "After Sorting <br/>" print_r($arr); ?>

task:2
With out using limit in query, display 2nd highest rank person
task 

programm

<?php
$arr = [50, 20, 35, 15, 45];

echo "Before Sorting <br/>";
print_r($arr);

// sorting logic start

$length = count($arr);
for ($i = 0; $i < $length - 1; $i++) {
    for ($j = 0; $j < $length - $i - 1; $j++) {
        if ($arr[$j] > $arr[$j + 1]) {
            // swap elements
            $temp = $arr[$j];
            $arr[$j] = $arr[$j + 1];
            $arr[$j + 1] = $temp;
        }
    }
}

// sorting logic end

echo "After Sorting <br/>";
print_r($arr);
?>

<!-- With out using limit in query, display 2nd highest rank person -->

<!-- SELECT Rank
FROM Persons
WHERE Rank < (SELECT MAX(Rank) FROM Persons)
ORDER BY Rank DESC -->

php tutorials from scratch index

 


https://webdevelopersera.blogspot.com/search/label/%40StudentTechMitra?updated-max=2024-05-08T18:36:00-07:00&max-results=20&start=28&by-date=false


https://webdevelopersera.blogspot.com/2024/05/advanced-php-tutoirials-from-scratch.html


https://webdevelopersera.blogspot.com/2024/05/advanced-php-tutoirials-from-scratch_8.html


https://webdevelopersera.blogspot.com/2024/05/blog-post.html

php tutorial -> develop bank applicaiton with oops concept

 bank_with_oops_o

index.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transaction Form</title>
</head>
<body>
<h2>Transaction Form</h2>
<form action="execution.php" method="post">
<label for="type">Type:</label>
<select name="type" id="type">
<option value="credit">Credit</option>
<option value="debit">Debit</option>
</select><br><br>
<label for="source">Source:</label>
<input type="text" name="source" id="source"><br><br>
<label for="amount">Amount:</label>
<input type="number" name="amount" id="amount" step="0.01"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

execution.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include('db.php'); // Include the database connection
include('bank_account.php'); // Include the BankAccount class

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$accountNumber = 11; // You might need to get the account number dynamically
$type = $_POST['type'];
$source = $_POST['source'];
$amount = $_POST['amount'];

// Create a new BankAccount object and pass the database connection
$account = new BankAccount($accountNumber, $conn);

// Execute transaction based on type
if ($type == 'credit') {
$account->deposit($amount);
} elseif ($type == 'debit') {
$account->withdraw($amount);
} else {
echo "Invalid transaction type";
}
}
?>

db.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password,$dbName);


// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// echo "Connected successfully";
?>

fetch.php


<?php
// fetch.php
require('db.php');
include('transaction.php');

// Fetch data from transactions table
$sql = "SELECT * FROM transactions";
$result = $conn->query($sql);
echo "<table>";
// Check if there are any rows returned
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["source"] . "</td>";
echo "<td>" . $row["amount"] . "</td>";
echo "<td>" . $row["created_at"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='5'>No transactions found</td></tr>";
}
echo "</table>";
$conn->close();
?>

bank_Account.php

<?php
include('db.php');

class BankAccount {
private $accountNumber;
private $balance;
private $conn; // Add a property to store the database connection

public function __construct($accountNumber, $conn) {
$this->accountNumber = $accountNumber;
$this->conn = $conn; // Store the database connection
// Initialize balance to 0
$this->balance = 0;
}
public function __destruct()
{
$this->getBalance();
}

public function deposit($amount) {
$conn = $this->conn; // Use the stored database connection
// Prepare and bind the SQL statement
$sql = "INSERT INTO transactions (type, source, amount, created_at) VALUES (?, ?, ?, NOW())";
$type = 'credit';
$source = 'deposit';
$timestamp = date("Y-m-d H:i:s");

$stmt = $conn->prepare($sql);
$stmt->bind_param("ssd", $type, $source, $amount);

// Execute the statement
if ($stmt->execute()) {
echo "Deposit recorded successfully </br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close statement
$stmt->close();
}

public function withdraw($amount) {
$conn = $this->conn; // Use the stored database connection
// Ensure balance is up to date
$this->getBalance();
if ($this->balance >= $amount) {
// Prepare and bind the SQL statement
$sql = "INSERT INTO transactions (type, source, amount, created_at) VALUES (?, ?, ?, NOW())";
$type = 'debit';
$source = 'withdrawal';
$timestamp = date("Y-m-d H:i:s");

$stmt = $conn->prepare($sql);
$stmt->bind_param("ssd", $type, $source, $amount);

// Execute the statement
if ($stmt->execute()) {
echo "Withdrawal recorded successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close statement
$stmt->close();
} else {
echo "Insufficient balance";
}
}

public function getBalance() {
$conn = $this->conn; // Use the stored database connection
// Prepare and bind the SQL statement to fetch all transactions
$sql = "SELECT SUM(CASE WHEN type='credit' THEN amount ELSE -amount END) AS balance FROM transactions";
$stmt = $conn->prepare($sql);
// Execute the statement
$stmt->execute();
// Get the result
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$this->balance = $row['balance'];
echo $row['balance'];
} else {
return 0; // No transactions found
}
}
}
?>

=

php tutorial -> develop bank appliaiton with oops

 bank_with_oops.php

bankaccount.php

<?php
include('db.php');

class bankAccount {

public $balance ;
public $type;
public $source;
public $amount;
public $conn;
public function __construct($type,$source,$amount,$conn){
$this->type=$type;
$this->source = $source;
$this->amount = $amount;
$this->conn = $conn;
}
public function __destruct(){
$this->fetch();
}
public function deposit(){
$conn= $this->conn;
$sql = "INSERT INTO transactions (type, source, amount) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssd", $this->type, $this->source, $this->amount);
// Execute the statement
if ($stmt->execute()) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
public function withdraw(){
$conn= $this->conn;
$sql = "INSERT INTO transactions (type, source, amount) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssd", $this->type, $this->source, $this->amount);
// Execute the statement
if ($stmt->execute()) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
public function fetch(){
$conn= $this->conn;
$sql = "SELECT * FROM transactions";
$result = $conn->query($sql);
echo "<table>";
// Check if there are any rows returned
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["source"] . "</td>";
echo "<td>" . $row["amount"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>No transactions found</td></tr>";
}
echo "</table>";
$conn->close();
}

}

db.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password,$dbName);


// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// echo "Connected successfully";
?>

execution.php

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

include('bankAccount.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$type = $_POST['type'];
$source = $_POST['source'];
$amount = $_POST['amount'];
$bank = new bankAccount($type,$source,$amount,$conn);

if($type =='credit')
{
$bank->deposit();
} else if($type =='debit')
{
$bank->withdraw();
} else {
echo 'none';
}
}

?>

index.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transaction Form</title>
</head>
<body>
<h2>Transaction Form</h2>
<form action="execution.php" method="post">
<label for="type">Type:</label>
<select name="type" id="type">
<option value="credit">Credit</option>
<option value="debit">Debit</option>
</select><br><br>
<label for="source">Source:</label>
<input type="text" name="source" id="source"><br><br>
<label for="amount">Amount:</label>
<input type="number" name="amount" id="amount" step="0.01"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

=

php tutorial -> bank applicaiton with direct query

 bank

create_table.php

<?php

include('db.php');

$sql = "CREATE TABLE transactions (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
type ENUM('credit', 'debit') NOT NULL,
amount DECIMAL(10,2) NOT NULL,
source VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";

if ($conn->query($sql) === TRUE) {
echo "TABLE created successfully";
} else {
echo "Error creating TABLE: " . $conn->error;
}

$conn->close();
?>

create_Transaction.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transaction Form</title>
</head>
<body>
<h2>Transaction Form</h2>
<form action="insert_transaction.php" method="post">
<label for="type">Type:</label>
<select name="type" id="type">
<option value="credit">Credit</option>
<option value="debit">Debit</option>
</select><br><br>
<label for="source">Source:</label>
<input type="text" name="source" id="source"><br><br>
<label for="amount">Amount:</label>
<input type="number" name="amount" id="amount" step="0.01"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

db.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password,$dbName);


// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo 'connected';
?>

fetch.php

<?php
require('db.php');

// Fetch data from transactions table
$sql = "SELECT * FROM transactions";
$result = $conn->query($sql);
echo "<table>";
// Check if there are any rows returned
if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["type"] . "</td>";
echo "<td>" . $row["source"] . "</td>";
echo "<td>" . $row["amount"] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>No transactions found</td></tr>";
}
echo "</table>";
$conn->close();
?>

insert_Transaction.php

<?php
include('db.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$type = $_POST['type'];
$source = $_POST['source'];
$amount = $_POST['amount'];

// Prepare and bind the SQL statement
$sql = "INSERT INTO transactions (type, source, amount) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssd", $type, $source, $amount);

// Execute the statement
if ($stmt->execute()) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close statement and connection
$stmt->close();
$conn->close();
}
?>

=


Hey Folks, It’s Worse Than We Thought — Claude’s Privacy Mess Just Got Bigger

  What started as a leak of shared Claude chats has turned into something much bigger — and much worse. The same thing is now happening with...