app/Http/Controllers/PostTagController.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)
    {
        $this->validate($request,[
            'title'=>'string|required',
            'status'=>'required|in:active,inactive'
        ]);
        $data=$request->all();
        $slug=Str::slug($request->title);
        $count=PostTag::where('slug',$slug)->count();
        if($count>0){
            $slug=$slug.'-'.date('ymdis').'-'.rand(0,999);
        }
        $data['slug']=$slug;
        $status=PostTag::create($data);
        if($status){
            request()->session()->flash('success','Post Tag Successfully added');
        }
        else{
            request()->session()->flash('error','Please try again!!');
        }
        return redirect()->route('post-tag.index');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'title' => 'string|required' , 'status' => 'required|in:active,inactive' ] ) ; $ data = $ request -> all ( ) ; $ slug = Str :: slug ( $ request -> title ) ; $ count = PostTag :: where ( 'slug' , $ slug ) -> count ( ) ; if ( $ count > 0 ) { $ slug = $ slug . '-' . date ( 'ymdis' ) . '-' . rand ( 0 , 999 ) ; } $ data [ 'slug' ] = $ slug ; $ status = PostTag :: create ( $ data ) ; if ( $ status ) { request ( ) -> session ( ) -> flash ( 'success' , 'Post Tag Successfully added' ) ; } else { request ( ) -> session ( ) -> flash ( 'error' , 'Please try again!!' ) ; } return redirect ( ) -> route ( 'post-tag.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .