Skip to content

Issue action with not an actual database column #528

@hamdallah90

Description

@hamdallah90

Hello,

i have created a media relation

`<?php

namespace App\Restify\Actions\User;

use App\Models\User;
use Binaryk\LaravelRestify\Actions\Action;
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;

class AttachUserAvatarRestifyAction extends Action
{
public function handle(RestifyRequest $request, User $user)
{
if ($request->hasFile('avatar')) {

        if ($user->avatar) {
            $user->avatar->delete();
        }
        
        $user->addMediaFromRequest('avatar')->toMediaCollection('avatars');

        return $user->avatar?->getUrl();
    }
}

}
`

and on UserRepository
field('avatar', fn () => $this->model()->avatar?->getUrl())->rules(['image'])->action(new AttachUserAvatarRestifyAction)

So all is good but i think the action trigger after the value of this field returns the old data returned.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions