PHP code example of lain / laravel-operator

1. Go to this page and download the library: Download lain/laravel-operator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lain / laravel-operator example snippets


$songs = Song::query()->get();

$preloaded = new PreloadJson($songs);
$preloaded->setJsonFields('artist_ids', 'compose_ids')
	->preload(Artist::query(), 'storedArtists', 'name', 'avatar');

return response()->success(SongResource::collection($songs));

public function toArray($request)
{
    return [
        'id' => $this->id,
        'name' => $this->name,
        'artists' => PreloadJson::fetchValue($this->storedArtists, $this->artist_ids),
        'composes' => PreloadJson::fetchValue($this->storedArtists, $this->compose_ids)
    ];
}