samedi 31 mars 2018

How to override the 'create' method when inserting into a related model. Laravel 5.5

I want to insert a new event (like a party ...etc) that is related to a user, so I do this according to this tutorial:

$event = $owner->events()->create( $request->all() );

However, I'd like to override the create method before inserting so according to this tutorial I do this in the app\Event:

public static function create(array $attributes = [])
        {
            error_log('Im here.');
            if ($attributes->privacy === "private") {
                /////
            }

            else {
                /////
            }

            $event = static::query()->create($attributes);

            return $event;
        }

My issue is that the code never reaches the new create method.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pQiqpU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire