PHP code example of brotzka / laravel-helper

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

    

brotzka / laravel-helper example snippets


    'providers' => [
        // ...
        // Other ServiceProvider 
        // ...
        Brotzka\LaravelHelper\HelperServiceProvider::class,
    ],

    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use App\BlogPost;
    
    use Brotzka\LaravelHelper\Helpers\SlugHelper;
    
    class YourController extends Controller {
        
        public function store(Request $request)
        {
            $post = new BlogPost();
            $post->title = $request->input('title');
            
            $slug = new SlugHelper('posts', 'mysql');
            $post->slug = $slug->createUniqueSlug($post->title);
            
            // ...
            $post->save();
        }
        
        public function update(Request $request, $id)
        {
            $post = BlogPost::findOrFail($id);
            $post->title = $request->input('title');
                    
            $slug = new SlugHelper('posts', 'mysql');
            $post->slug = $slug->createUniqueSlug($post->title, $post->id);
                 
            // ...
            $post->save();
        }
    }