PHP code example of matejsvajger / laravel-distillery
1. Go to this page and download the library: Download matejsvajger/laravel-distillery 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/ */
matejsvajger / laravel-distillery example snippets
namespace App\Models
use Illuminate\Database\Eloquent\Model;
use matejsvajger\Distillery\Traits\Distillable;
class Product extends Model {
use Distillable;
protected $distillery = [
'hidden' => [
//
],
'default' => [
//
]
];
...
}
class ProductListController extends Controller
{
public function index()
{
return view('product.list',[
'products' => Product::distill()
]);
}
}
namespace App\Filters\Product;
use Illuminate\Database\Eloquent\Builder;
use matejsvajger\Distillery\Contracts\Filter;
class Search implements Filter
{
public static function apply(Builder $builder, $value)
{
return $builder->where(function ($query) use ($value) {
$query
->where('name', 'like', "{$value}%")
->orWhere('description', 'like', "%{$value}%");
});
}
}
public function list(Request $request, Category $category)
{
return view('product.list',[
'products' => Product::distill([
'category' => $category->id,
]);
]);
}
Distillery::distill(Product::class, $filters);
class User extends Model {
protected $distillery = [
'default' => [
'sort' => 'updated_at-desc'
]
];
}
class User extends Model {
protected $distillery = [
'hidden' => [
'category' // - applied in controller; set from seo url
]
];
}
class User extends Model {
protected $distillery = [
'fallback' => true
];
}