PHP code example of brahmic / laravel-filler

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

    

brahmic / laravel-filler example snippets




namespace App\Http\Controllers;

use App\Post;
use Exception;
use Brahmic\Filler\Filler;
use Illuminate\Http\Request;

class PostController
{
 /**
 * @param $id
 * @param Request $request
 * @param Filler $filler
 * @return Post
 * @throws Exception
 */
 public function put(Request $request, Filler $filler): Post
 {
     $post = Post::findOrNew($request->get('id'));
     $filler->filler($post, $request->all());
    
     // here we can do something before the changes are sent to the database.
    
     $filler->flush();
    
     return $post;
 }
}

 $user = $filler->filler(User::class, [
 'id' => '123e4567-e89b-12d3-a456-426655440000',
 'name' => 'Brahmic',
 'email' => '[email protected]',
 'roles' => [
         [
             'id' => 'dcb41b0c-8bc1-490c-b714-71a935be5e2c',
             'pivot' => ['sort' => 0],
         ],
     ],
 ]);

 $user->relationLoaded('roles'); // true
 // although the flush has not been done yet, all relationships have already been registered, and there is no need to load them additionally.
 // Calling $user->roles will not cause a repeated request to the database.

 $filler->flush();
 // Only after this the entity with all its connections will be