PHP code example of abdullah-karam / laravel-svg

1. Go to this page and download the library: Download abdullah-karam/laravel-svg 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/ */

    

abdullah-karam / laravel-svg example snippets




namespace App\Http\Controllers;

use Abdullah\LaravelSvg\Facades\LaravelSvg;
use App\Models\User;

class UserController extends Controller
{
    public function generateSvg(User $user)
    {
        $svgDetails = LaravelSvg::svgFor(words: $user->fullname)->generate(); 
        dd($svgDetails);
    }
}


array:6 [▼
  "name" => "64af002c8ba51.svg"
  "path" => "users/64af002c8ba51.svg"
  "full_path" => "http://localhost:8000/storage/users/64af002c8ba51.svg"
  "mime_type" => "image/svg+xml"
  "size" => 422
  "disk" => "public"
]



namespace App\Http\Controllers;

use Abdullah\LaravelSvg\Facades\LaravelSvg;
use App\Models\User;

class UserController extends Controller
{
    public function generateSvg(User $user)
    {
        $svgDetails = LaravelSvg::svgFor(words: $user->fullname)
                                  ->logoText()->generate(); 
        dd($svgDetails);
    }
}


array:6 [▼ 
  "name" => "64af03da5f35c.svg"
  "path" => "users/64af03da5f35c.svg"
  "full_path" => "http://localhost:8000/storage/users/64af03da5f35c.svg"
  "mime_type" => "image/svg+xml"
  "size" => 414
  "disk" => "public"
]



return [
    'folder' => 'storage', ## default folder name in public folder
    'default_logo_text' => 'logo', ## default logo text
    'logo_text_color' => '#000000',
    'avatar_text_color' => '#f1c40f',
    'avatar_background_color' => '#ffffff',
    'default_svg_path' => 'users', ## folder name will be created in public/{folder}/users
    'hash_svg_name' => true ## if you want to hash svg name by default true
];

php artisan vendor:publish --provider="Abdullah\LaravelSvg\LaravelSvgServiceProvider" --tag="config"