app/Http/Controllers/Admin/PostController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $validateData = $request->validate([
            'title' => 'required|max:240',
            'content' => 'required',
        ]);
        $data = $request->all();
        $slug = Str::slug($data['title'], '-');
        $postPresente = Post::where('slug', $slug)->first();
        $counter = 0;
        while ($postPresente) {
            $slug = $slug . '-' . $counter;
            $postPresente = Post::where('slug', $slug)->first();
            $counter++;
        }
        $newPost = new Post();
        $newPost->fill($data);
        $newPost->slug = $slug;
        $newPost->save();
        return redirect()->route('admin.posts.show', ['post' => $newPost]);
    }
public function store ( Request $ request ) { $ validateData = $ request -> validate ( [ 'title' => 'required|max:240' , 'content' => 'required' , ] ) ; $ data = $ request -> all ( ) ; $ slug = Str :: slug ( $ data [ 'title' ] , '-' ) ; $ postPresente = Post :: where ( 'slug' , $ slug ) -> first ( ) ; $ counter = 0 ; while ( $ postPresente ) { $ slug = $ slug . '-' . $ counter ; $ postPresente = Post :: where ( 'slug' , $ slug ) -> first ( ) ; $ counter ++ ; } $ newPost = new Post ( ) ; $ newPost -> fill ( $ data ) ; $ newPost -> slug = $ slug ; $ newPost -> save ( ) ; return redirect ( ) -> route ( 'admin.posts.show' , [ 'post' => $ newPost ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .