承接 mariale098/quotes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mariale098/quotes

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mariale098/quotes

包简介

A Laravel package for interacting with the DummyJSON Quotes API

README 文档

README

A Laravel package for interacting with the DummyJSON Quotes API. This package provides a simple way to fetch and display quotes with caching and rate limiting.

Installation

  1. Create a new Laravel project:
composer create-project laravel/laravel [project-name]
  1. Install the package via Composer:
composer require mariale098/quotes
  1. Publish the configuration file:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="config"
  1. Publish the assets:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="assets"
  1. Publish the quotes-styles:
php artisan vendor:publish --provider="Mariale098\Quotes\QuotesServiceProvider" --tag="quotes-styles" --force
  1. Configure your Laravel project's .env file with the following settings:
# Session Configuration
SESSION_DRIVER=file
# This setting stores session data in files, which is required for the quotes package to work properly

# Cache Configuration
CACHE_STORE=file
# This setting enables file-based caching for storing quotes data

# Queue Configuration
QUEUE_CONNECTION=sync
# This setting ensures that quote operations are processed synchronously

These settings are essential for the proper functioning of the quotes package, as they:

  • Enable session management for user interactions
  • Provide caching capabilities for API responses
  • Ensure synchronous processing of quote operations

Usage

API Endpoints

The package provides the following API endpoints:

  • GET /api/quotes/random - Fetches a random quote from the API
  • GET /api/quotes - Retrieves a paginated list of quotes (supports limit and skip parameters)
  • GET /api/quotes/{id} - Gets a specific quote by its ID

Vue Component Integration

The package includes a Vue.js component for displaying quotes. Follow these steps to integrate it into your application:

  1. Update your welcome.blade.php view to include the Vue app container and necessary assets:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel Quotes</title>
        @vite(['resources/css/app.css'])
    </head>
    <body>
        <div id="app"></div>
        @vite(['resources/js/app.js'])
    </body>
</html>
  1. Import and mount the component in your resources/js/app.js:
import { createApp } from 'vue';
import QuotesComponent from './components/QuotesComponent.vue';

createApp(QuotesComponent).mount("#app");
  1. Configure Vite by updating your vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import tailwindcss from '@tailwindcss/vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        tailwindcss(),
        vue(),
    ],
});
  1. Install Vue.js dependencies and build the assets:
npm install @vitejs/plugin-vue vue
npm run build
  1. Start the Laravel development server to test your application:
php artisan serve

Features

  • Random Quote Display: Shows a random quote that changes on page reload
  • Quote Search: Search for quotes by their ID
  • Paginated Quotes List: Browse through quotes with pagination
  • Error Handling: User-friendly error messages
  • Responsive Design: Mobile-friendly interface
  • Caching: Built-in caching for API responses
  • Rate Limiting: Protection against API abuse

Configuration

Customize the package behavior by modifying the config/quotes.php file:

return [
    'cache_ttl' => 3600, // Cache time in seconds (1 hour)
    'rate_limit' => [
        'enabled' => true,
        'max_attempts' => 50, // Maximum API calls per minute
        'decay_minutes' => 1,
    ],
];

Author

Maria Alejandra Garcia Raiola (marialejandra.g98@gmail.com)

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-29