1. Go to this page and download the library: Download webdev/laravel-loader 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/ */
webdev / laravel-loader example snippets
composer
namespace App\Models;
use WebDev\Loader\LoaderMacro;
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model
{
use LoaderMacro;
}
$product = Product::findOrFail($id);
return $product->loader(
new ProductTranslate(new Language()),
new ProductFeature(new Language()),
'categories'
);
class ProductTranslate extends Loader
{
protected $name = 'translate';
// Translate
public function init()
{
return ProductTranslate::where('product_id', $this->getModel()->id)
->where('language_id' => auth()->user()->language_id)
->firts()
->toArray();
}
}
class ProductFeature extends Loader
{
protected $name = 'features';
// Features
public function init()
{
return ProductFeature::where('product_id', $this->getModel()->id)->get()->toArray();
}
}
class Language extends Loader
{
protected $name = 'language';
// Feature
public function init()
{
return Language::findOrFail($this->getPrevious()->language_id)->toArray();
}
}