forteirp
5 months ago
154
6
Laravel

How to get a excerpt from the input data from the body?

Posted 5 months ago by forteirp

What I want to do is to use the first 100 words that have been inputted from my body input as the excerpt input on my database... I think I need to modify my store function to do this? But I'm not sure how to do that correctly. I looked up the "only" and "except" methods, but I am not sure how it works if I only want the first 100 words of the body input?

This is my store function

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
    }

and here's my phpMyadmin to excerpt column... https://i.stack.imgur.com/segmG.jpg

Let me know if you need more information from me, to help was this issue...

Please sign in or create an account to participate in this conversation.