PHP code example of joelshepherd / create-with

1. Go to this page and download the library: Download joelshepherd/create-with 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/ */

    

joelshepherd / create-with example snippets



use JoelShepherd\CreateWith;

class Example extends Model
{
    use CreateWith\Uuid;
}



$example = Example::create();
$example->uuid; // 123e4567-e89b-12d3-a456-426655440000


use JoelShepherd\CreateWith;

class Example extends Model
{
    use CreateWith\Slug;

    // Optionally set the base string to build the slug from
    protected function getSlugBaseText()
    {
        return $this->title;
    }
}



// Creates a unique slug from the base text
$example = Example::create([
    'title' => 'This is a title'
]);
$example->slug; // this-is-a-title

// Uniqueness is retained even with the same base text
$example2 = Example::create([
    'title' => 'This is a title'
]);
$example2->slug; // this-is-a-title-7iw90lj


use JoelShepherd\CreateWith\WithIpAddress;

class Example extends Model
{
    use CreateWith\IpAddress;
}



$example = Example::create();
$example->ip_address; // 127.0.0.1