PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved

how to add new action

mostafa-khattab

Jun 7th, 2017 08:35 AM

hi I love this admin panel but I can't figure out how to add new controller action EX : add activate action to pages module ... I tried to use my own controller but for this, i have to rebuild the entire module from scratch again ... can I override or extend the main controller ============ last issue ... how can i insert the (auth()->user()->id) automaticlly in the author_id field when inserting data

devdojo

Jun 16th, 2017 09:22 PM

Hey There :)

What kind of action are you trying to add? Are you trying to add some new functionality in a view?

Additionally, if you want the current logged in Author ID to be saved you can add this method to your App\Post.php model, or whichever model you want to assign an author ID when it has been saved:

public function save(array $options = [])
{
    // If this is only a new create
    if (! isset($this->id)) {
        // Add the user id as the Author of the post
        $this->author_id = Auth::user()->id;
        parent::save();
    } else {
        parent::save();
    }
}

Add that to the model and the logged in user id will be stored in author_id field, or you may want to change it to the field that you want to add the User or Author ID.

Hope that helps. Thanks.

chist3r

Aug 2nd, 2017 03:15 PM

Why having parent::save() twice while you can have it once?

public function save(array $options = [])
{
    // If this is only a new create
    if (! isset($this->id)) {
        // Add the user id as the Author of the post
        $this->author_id = Auth::user()->id;
    }
        
    parent::save();
}