PHP code example of mortezaa97 / brands

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/ */

    

mortezaa97 / brands example snippets


'providers' => [
    // ...
    Mortezaa97\Brands\BrandsServiceProvider::class,
],

return [
    'table_name' => 'brands', // Customize table name if needed
];

use Mortezaa97\Brands\Models\Brand;

$brand = Brand::create([
    'name' => 'Adidas',
    'slug' => 'adidas',
    'logo' => 'path/to/logo.png',
    'status' => Status::ACTIVE,
    'category_id' => 1,
    'desc' => 'Premium sportswear brand',
    'meta_title' => 'Adidas Official',
    'color' => '#000000',
    'created_by' => auth()->id(),
]);

// 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::find(1);
$brand->update([
    'name' => 'Updated Brand Name',
    'updated_by' => auth()->id(),
]);

$brand = Brand::find(1);
$brand->delete(); // Soft delete

// Restore
$brand->restore();

// Force delete
$brand->forceDelete();

$brand = Brand::with('category')->first();
$categoryName = $brand->category->name;

$brand = Brand::with('createdBy')->first();
$creatorName = $brand->createdBy->name;

$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();
bash
php artisan vendor:publish --provider="Mortezaa97\Brands\BrandsServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Mortezaa97\Brands\BrandsServiceProvider" --tag="migrations"
bash
php artisan migrate