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
}
}
No comments:
Post a Comment