1. Go to this page and download the library: Download mortezaa97/brands 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/ */
// Get all active brands
$brands = Brand::all();
// Get brand by slug
$brand = Brand::where('slug', 'nike')->first();
// Get brands with category
$brands = Brand::with('category')->get();
// Get brands created by specific user
$brands = Brand::whereHas('createdBy', function($query) {
$query->where('id', 1);
})->get();
$brand = Brand::with('updatedBy')->first();
if ($brand->updatedBy) {
$updaterName = $brand->updatedBy->name;
}
use Illuminate\Support\Facades\Gate;
// Check if user can view brands
if (Gate::allows('viewAny', Brand::class)) {
// User can view brands
}
// Authorize specific brand action
Gate::authorize('update', $brand);
use Mortezaa97\Brands\Http\Resources\BrandResource;
return new BrandResource($brand);
use Mortezaa97\Brands\Http\Resources\BrandSimpleResource;
return BrandSimpleResource::collection($brands);
use Mortezaa97\Brands\BrandsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
BrandsPlugin::make(),
]);
}
use Mortezaa97\Brands\BrandsFacade as Brands;
// Use the facade
Brands::someMethod();