Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Formattable Trait #1

Merged
merged 1 commit into from
Mar 23, 2015
Merged

Add Formattable Trait #1

merged 1 commit into from
Mar 23, 2015

Conversation

RomainLanz
Copy link
Contributor

Hey @jarektkaczyk!

馃毀 We have collision problems with our method setAttribute. How can we handle that?

With that we can easily format our attributes.

class User
{
    use Formattable;

    protected $formats = [
        'first_name' => ['strtolower', 'ucwords],
        'last_name' => 'strtolower|ucwords',
        'phone' => 'formatPhone',
        'slug' => '\Str@slug',
    ];

    public function formatPhone($phone)
    {
        return "({$phone})";
    }
}

$user->first_name = 'roMAin'; // Will set 'Romain'
$user->last_name = 'laNZ'; // Will set 'Lanz'
$user->phone = 555; // Will set '(555)'
$user->slug = 'Awesome package!'; // Will set 'awesome-package'

I also change the readme to be better and to document Formattable.

@RomainLanz
Copy link
Contributor Author

Why not create an organisation and put all of these add-on on their own repository?

Btw, we can create 脿 package nammed hookable to register hook into Eloquent. With that we wouldn't have any problems with some collisions.

@RomainLanz RomainLanz closed this Mar 20, 2015
@RomainLanz RomainLanz reopened this Mar 20, 2015
@jarektkaczyk
Copy link
Owner

Hey, exactly that's the problem we have to solve. I thought about macros, but that's also tricky. I will think about it.

@RomainLanz
Copy link
Contributor Author

Maybe ask Taylor to add some hook into Eloquent.

@RomainLanz
Copy link
Contributor Author

I didn't see any way to do that except to create a package like eloquent-hook to hook into Eloquent process.

@RomainLanz
Copy link
Contributor Author

Any news about this?

Maybe my code need some refactoring.

@jarektkaczyk
Copy link
Owner

Hey Romain, I've been out and busy now, so haven't got the chance to work on it so far. Mergin this one and I will think about the solution later.

jarektkaczyk added a commit that referenced this pull request Mar 23, 2015
@jarektkaczyk jarektkaczyk merged commit 7753d92 into jarektkaczyk:master Mar 23, 2015
@jarektkaczyk
Copy link
Owner

Oh and btw I'm against validation on the model ;)

@RomainLanz
Copy link
Contributor Author

@jarektkaczyk Hey, no problem, I'm just writing that to have some stuff on the roadmap :p

@RomainLanz RomainLanz deleted the formattable branch March 23, 2015 14:51
@belguinan belguinan mentioned this pull request Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants