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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You can achieve this by using your own custom model and [eloquent models events](https://laravel.com/docs/5.6/eloquent). #113

Closed
bloodykheeng opened this issue Feb 7, 2024 · 2 comments

Comments

@bloodykheeng
Copy link

          You can achieve this by using your own custom model and [eloquent models events](https://laravel.com/docs/5.6/eloquent).
  1. Create a new model class like this (untested):
namespace App\Models;

class YourStatusModel extends \Spatie\ModelStatus\Status

public static function boot()
{
   // this function will automatically be executed by Laravel when a new `Status` is being created.
    static::creating(function(YourStatusModel $status) {
        $status->causer_id = optional(auth()->user())->id;
    });
}
  1. Set that class in the status_model key of the model-status config file.

  2. Create a migration that adds caused_id to the statuses table.

  3. Profit!

Originally posted by @freekmurze in #38 (comment)

@bloodykheeng
Copy link
Author

i want to be able to pass in the id of the auth user so that at the end of the day when am pulling the statuses attached to the model i can get the detail of that user who made comment

by the way I would like to thank the creators of this package its really nice thanks alot though its lacking this feature anyone to guide me how to achieve this

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

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

No branches or pull requests

2 participants