app/Http/Controllers/Dashboard/Videos.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)
    {
        $validated = request()->validate([
            'name'          => ['required' , 'max:191'],
            'des'           => ['required' , 'min:10'],
            'meta_keywords' => ['max:191'],
            'meta_des'      => ['max:191'],
            'youtube'       => ['required' ,'min:10' , 'url'],
            'published'     => ['required'],
            'image'         => ['required' , 'image'],
            'cat_id'        => ['required' ,'integer'],
            'skills'        => ['required'] , 
            'tags'          => ['required']
            ]);    
         $file = request()->file('image');
         $fileName = time().Str::random('10').'.'.$file->getClientOriginalExtension();
         $file->move( public_path('uploads') , $fileName ); 
         $validated['image'] = $fileName ;       
         $row = Video::create($validated  +  ['user_id' => auth()->user()->id] );
         $row->skills()->sync( $validated['skills'] );
         $row->tags()->sync( $validated['tags'] );
        alert()->success('Video is Saved' , 'Done');
        return redirect()->route('videos.index');
    }
public function store ( Request $ request ) { $ validated = request ( ) -> validate ( [ 'name' => [ 'required' , 'max:191' ] , 'des' => [ 'required' , 'min:10' ] , 'meta_keywords' => [ 'max:191' ] , 'meta_des' => [ 'max:191' ] , 'youtube' => [ 'required' , 'min:10' , 'url' ] , 'published' => [ 'required' ] , 'image' => [ 'required' , 'image' ] , 'cat_id' => [ 'required' , 'integer' ] , 'skills' => [ 'required' ] , 'tags' => [ 'required' ] ] ) ; $ file = request ( ) -> file ( 'image' ) ; $ fileName = time ( ) . Str :: random ( '10' ) . '.' . $ file -> getClientOriginalExtension ( ) ; $ file -> move ( public_path ( 'uploads' ) , $ fileName ) ; $ validated [ 'image' ] = $ fileName ; $ row = Video :: create ( $ validated + [ 'user_id' => auth ( ) -> user ( ) -> id ] ) ; $ row -> skills ( ) -> sync ( $ validated [ 'skills' ] ) ; $ row -> tags ( ) -> sync ( $ validated [ 'tags' ] ) ; alert ( ) -> success ( 'Video is Saved' , 'Done' ) ; return redirect ( ) -> route ( 'videos.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// dd(request()->all()); // Video::skills()->sync($validated['skills']) // $skills[] = request()->skills; // dd(request()->skills);