Usage
I. Auth
laravel/sanctum: Laravel Sanctum provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs. Sanctum allows each user of your application to generate multiple API tokens for their account. These tokens may be granted abilities / scopes which specify which actions the tokens are allowed to perform.
Routes can be protected like this
Route::middleware(['auth:sanctum'])->group(function () {
// routes
}
Login 419 error: "CSRF token mismatch"
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
php artisan optimize:clear
II. API documentation
knuckleswtf/scribe: Scribe helps you generate API documentation for humans from your Laravel/Lumen/Dingo codebase. See a live example at demo.scribe.knuckles.wtf.
If you use php artisan serve
, knuckleswtf/scribe is available on /docs
, like localhost:8000/docs. You can set parameters into each Controller, check scribe.knuckles.wtf/laravel to know more, like this
<?php
/**
* @group Author
*
* Endpoint to get Authors data.
*/
class AuthorController extends Controller
{
/**
* GET Author collection
*
* <small class="badge badge-blue">WITH PAGINATION</small>
*
* You can get all Authors with alphabetic order on lastname with pagination.
*
* @queryParam perPage int Entities per page, '32' by default. No-example
* @queryParam page int The page number, '1' by default. No-example
* @responseFile public/assets/responses/authors.index.get.json
*/
public function index(Request $request)
{
// ...
}
}
Generate documentation
php artisan scribe:generate
III. Code linter
IDE helper
barryvdh/laravel-ide-helper: to generate magic methods for each model to help IDE completion
composer helper
larastan
nunomaduro/larastan: Adds static analysis to Laravel improving developer productivity and code quality.
php artisan larastan
PHP CS Fixer
friendsofphp/php-cs-fixer: A tool to automatically fix PHP Coding Standards issues
composer helper
IV. Database and models
- fakerphp/faker: Faker is a PHP library that generates fake data for you
Enum
spatie/laravel-enum: Laravel support for spatie/enum
Media library
spatie/laravel-medialibrary: Associate files with Eloquent models. If you update registerMediaConversions()
in any Model, you can regenerate conversions
php artisan media-library:regenerate
Tags
spatie/laravel-tags: Add tags and taggable behaviour to your Laravel app
V. Tools
Browser Sync
- BrowserSync/browser-sync: Keep multiple browsers & devices in sync when building websites.
To enable or disable Browser Sync, just change variable in .env
BROWSER_SYNC=true
Clockwork
itsgoingd/clockwork: Clockwork is a development tool for PHP available right in your browser. Clockwork gives you an insight into your application runtime - including request data, performance metrics, log entries, database queries, cache queries, redis commands, dispatched events, queued jobs, rendered views and more - for HTTP requests, commands, queue jobs and tests.
To use Clockwork, you have to install browser extension: Chrome or Firefox. When it's done, just open DevTools and choose Clockwork.
CORS
fruitcake/laravel-cors: Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
Images
- spatie/image: Manipulate images with an expressive API
- oscarotero/inline-svg: Insert svg in the html so you can use css to change the style
- spatie/laravel-image-optimizer: Optimize images in your Laravel app
Markdown
- thephpleague/commonmark: Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
- spatie/commonmark-highlighter: Highlight code blocks with league/commonmark
- thephpleague/html-to-markdown: Convert HTML to Markdown with PHP
- spatie/laravel-markdown: A highly configurable markdown renderer and Blade component for Laravel
XML
spatie/array-to-xml: A simple class to convert an array to xml
Routing
spatie/laravel-route-attributes: Use PHP 8 attributes to register routes in a Laravel app
Telescope
Only available on routes/web.php
- laravel/telescope: Telescope makes a wonderful companion to your local Laravel development environment. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.
- fruitcake/laravel-telescope-toolbar: A toolbar for Laravel Telescope, based on the Symfony Web Profiler.
To enable Telescope, just change variable in .env
TELESCOPE_ENABLED=true
Note: only useful in local
You can use laravel/telescope on the application at http://localhost:8000/telescope if you serve project with php artisan serve
(adapt URL if you have VHost).
VI. Tests
- phpunit.de:
phpunit/phpunit
package doc - pestphp.com:
pestphp/pest
package doc
php artisan migrate --database=testing
You can run Pest and PHP Unit tests
php artisan pest:run