This README provides instructions for setting up and running the Laravel 10 project with user authentication and different roles (admin and user).
Before running the project, ensure your development environment meets the following requirements:
- PHP >= 7.4
- Composer
- Node.js >= 14.x
- npm or Yarn
- Apache or Nginx web server
- MySQL or PostgreSQL database
Follow these steps to set up the Laravel project:
-
Clone the Repository
git clone https://github.com/prasetiyo28/laravel-blog.git cd laravel-blog
-
Install Composer Dependencies
git clone composer install
- Install npm Dependencies
npm install
- Create a Copy of the .env File
cp .env.example .env
- Generate Application Key
php artisan key:generate
- Set Up Database
- Create a new database for your project.
- Update .env file with database credentials:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
- Run database migrations to create tables:
- Set Up Database
- If you want to seed the database with dummy data (e.g., admin and user roles):
php artisan db:seed
- Development Server Start the Laravel development server:
php artisan serve
npm run dev
Access the application in your web browser at http://localhost:8000.
php artisan test
Authentication and Authorization
- Roles: There are two types of users: admin and user.
- Admin Privileges:
- Create, read, update, and delete posts. Manage users (optional).
- User Privileges:
- Read posts.
- Comment on posts.
Routes
- /login: Login page for users.
- /register: Registration page for new -users.
- /posts: List of posts visible to users.
- /posts/{id}: View a specific post.
- /posts/create (Admin): Create a new post.
- /posts/{id}/edit (Admin): Edit an existing post.
- /posts/{id}/delete (Admin): Delete a post.
Additional Features
- Comments: Users can comment on posts.
- Pagination: Paginate posts for better navigation.
- Middleware: Use middleware to manage access control based on user roles.
API
- postman collection link