PHP Framework
Laravel
Sight! A killer component that speeds up Laravel development is now open source!Sight! A killer component that speeds up Laravel development is now open source!
The following is introduced to you by the Laravel tutorial column! , I hope it will be helpful to friends in need!

Today, I recommend a Laravel-specific component: Sight
Laravel development speed can be regarded as the fastest. However, if you add Sight now, your development speed will be even faster.
What did Sight do?
Sight implemented a Presenter layer on the Server Side. This allows you to easily convert the data retrieved from the server into displayable data. Since the introduction of Sight, Laravel has become the only framework that supports the MVP model of the Server Side.
Why use Sight?
First, it is to speed up development.
2. Domestic Phpers all know that large manufacturers prohibit SQL joins of more than three tables. For beginners, you will query the database in a FOR loop. If you have banned it, it is possible that they have PLUCKed out the relevant ID. Find out the results, and then nest a FOR loop within a FOR loop to check related associated data.
Sight provides a very good Pluck function. After finding the ID, request the relevant data and hand it over to Sight, and Sight will splice the data for you. What it does is organize the data by associating the ID with the KEY. This greatly improves program efficiency.
3. The use of Sight is quite simple.
For example, the following example is almost similar to the use of Model.
namespace App\Presenter
use Bardoqi\Sight\Presenter;
use Bardoqi\Sight\Traits\PresenterTrait;
use Bardoqi\Sight\Enums\MappingTypeEnum
use Bardoqi\Sight\Enums\PaginateTypeEnum
use App\Repositories\ArticleRepository;
use App\Repositories\UserRepository;
class ArticlePresenter extents Presenter
{
use PresenterTrait;
public function getArticleList($where)
{
$articleArray = ArticleRepository::getList($where);
$user_ids = $this->selectFields('id','title','created_at','created_by')
->fromLocal($articleArray,'articles')
->pluck('created_by');
$users = UserRepository::getUsersWithIds($user_ids);
$this->innerJoinForeign($users,'userss')
->onRelationByObject(Relation::of()
->localAlias('articles')
->localField('created_by')
->foreignAlias('users')
->foreighField('id'))
->addFieldMappingByObject(FieldMapping::of()
->key('created_at')
->src('created_at')
->type(MappingTypeEnum::METHOD_NAME))
->addFieldMappingByObject(FieldMapping::of()
->key('created_by')
->src('user_name')
->type(MappingTypeEnum::JOIN_FIELD));
return $this->toPaginateArray(PaginateTypeEnum::PAGINATE_API);
}
}In the above example, the code converts created_at from int to time, and converts created_by from user id to user name.
We see that: created_at uses MappingTypeEnum::METHOD_NAME. Where is this method? It is in PresenterTrait. Therefore, you can also define your own Traits.
created_by directly reads the user_name in the associative array because MappingTypeEnum::JOIN_FIELD is used.
The above code seems a bit long, but onRelationByObject() can use onRelation() parameter passing method instead, and the code will be shorter.
Same as addFieldMappingByObject(), instead use addFieldMappingList() to pass in an array, and the code is shorter.
Sight is far more than just this feature. It not only supports data retrieved by MySQL, but also supports data retrieved by ElasticSearch.
Although it is a pure array operation, it also has innerJoin and outerJoin, and has hasOne, hasMany...
Of course, there are more functions, you have to read the documentation carefully.
Sight tries to solve the problem of converting the data into displayable data after you find it. It does a good job and can really make you Coding More Happy; Coding More Quickly!
Github address: https://github.com/BardoQi/Sight
Sight - the killer component that speeds up Laravel development is now open source! Hurry up FORK, Hurry up to STAR!
The above is the detailed content of Sight! A killer component that speeds up Laravel development is now open source!. For more information, please follow other related articles on the PHP Chinese website!
Laravel framework skills sharingApr 18, 2025 pm 01:12 PMIn this era of continuous technological advancement, mastering advanced frameworks is crucial for modern programmers. This article will help you improve your development skills by sharing little-known techniques in the Laravel framework. Known for its elegant syntax and a wide range of features, this article will dig into its powerful features and provide practical tips and tricks to help you create efficient and maintainable web applications.
The difference between laravel and thinkphpApr 18, 2025 pm 01:09 PMLaravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.
Laravel user login function listApr 18, 2025 pm 01:06 PMBuilding user login capabilities in Laravel is a crucial task and this article will provide a comprehensive overview covering every critical step from user registration to login verification. We will dive into the power of Laravel’s built-in verification capabilities and guide you through customizing and extending the login process to suit specific needs. By following these step-by-step instructions, you can create a secure and reliable login system that provides a seamless access experience for users of your Laravel application.
What versions of laravel are there? How to choose the version of laravel for beginnersApr 18, 2025 pm 01:03 PMIn the Laravel framework version selection guide for beginners, this article dives into the version differences of Laravel, designed to assist beginners in making informed choices among many versions. We will focus on the key features of each release, compare their pros and cons, and provide useful advice to help beginners choose the most suitable version of Laravel based on their skill level and project requirements. For beginners, choosing a suitable version of Laravel is crucial because it can significantly impact their learning curve and overall development experience.
How to view the version number of laravel? How to view the version number of laravelApr 18, 2025 pm 01:00 PMThe Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.
The latest method of using php framework laravelApr 18, 2025 pm 12:57 PMLaravel is a popular PHP-based web application framework that is popular among developers for its elegant syntax and powerful features. Its latest version introduces many improvements and new features designed to improve the development experience and application performance. This article will dive into Laravel's latest approach, focusing on how to leverage these updates to build more powerful and efficient web applications.
Laravel framework installation methodApr 18, 2025 pm 12:54 PMArticle summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.
How to learn Laravel How to learn Laravel for freeApr 18, 2025 pm 12:51 PMWant to learn the Laravel framework, but suffer from no resources or economic pressure? This article provides you with free learning of Laravel, teaching you how to use resources such as online platforms, documents and community forums to lay a solid foundation for your PHP development journey from getting started to master.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools





