Skip to content

CRUD: generate slug before function rules #1813

Answered by taiwanleaftea
falconandrea asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, you can do it following way (in PostEditScreen):

 public function createOrUpdate(Post $post, Request $request)
 {
        // skipped

        $arr = $request->input('post');
        $merged = array_merge(['slug' => Str::slug($request->input('post.title'))], $arr);

        $request->merge(['post' => $merged]);

        $validated = Validator::make($request->get('post'), [
            'title' => 'required|max:255',
            'slug' => [
                'required',
                Rule::unique('posts')->ignore($post->id),
            ],
            // additional validation rules here
        ])->validate();

        // $validated array with validated input, including slug

        $po…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@falconandrea
Comment options

Answer selected by falconandrea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants