app/Http/Controllers/AchatPacksController.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)
    {
        $pack = Pack::find($request['pack_id']);
        $interval = $pack->jour;        
        $achatpack = AcheterPack::create([
            'user_id'           => Auth::id(),
            'pack_id'           => $request['pack_id'],
            'date_achat'        => $request['date_achat'],
            'date_fin'          => date('Y-m-d', strtotime($request['date_achat']. ' + ' . $interval .' days')),
            'statut_pack'       => 0
        ]);
        if($achatpack){
            if($request['fichier'] != null){
                $file = $request->file('fichier');
                $mime = mime_content_type($file->getPathName());
                if(strstr($mime, "video/")){
                    $video = $achatpack->id.'.'.$file->getClientOriginalExtension();
                    if (!file_exists(public_path('images/achatpacks'))) {
                        mkdir(public_path('images/achatpacks'));
                    }
                    $file->move(public_path('images/achatpacks'), $video);
                    $achatpack->video = "images/achatpacks/".$video;
                    $achatpack->save();
                }else if(strstr($mime, "image/")){
                    $image = $achatpack->id.'.'.$file->getClientOriginalExtension();
                    if (!file_exists(public_path('images/achatpacks'))) {
                        mkdir(public_path('images/achatpacks'));
                    }
                    $file->move(public_path('images/achatpacks'), $image);
                    $achatpack->image = "images/achatpacks/".$image;
                    $achatpack->save();
                }
            }
            return redirect()->route('packpubs.index');
        }
    }
public function store ( Request $ request ) { $ pack = Pack :: find ( $ request [ 'pack_id' ] ) ; $ interval = $ pack -> jour ; $ achatpack = AcheterPack :: create ( [ 'user_id' => Auth :: id ( ) , 'pack_id' => $ request [ 'pack_id' ] , 'date_achat' => $ request [ 'date_achat' ] , 'date_fin' => date ( 'Y-m-d' , strtotime ( $ request [ 'date_achat' ] . ' + ' . $ interval . ' days' ) ) , 'statut_pack' => 0 ] ) ; if ( $ achatpack ) { if ( $ request [ 'fichier' ] != null ) { $ file = $ request -> file ( 'fichier' ) ; $ mime = mime_content_type ( $ file -> getPathName ( ) ) ; if ( strstr ( $ mime , " video/ " ) ) { $ video = $ achatpack -> id . '.' . $ file -> getClientOriginalExtension ( ) ; if ( ! file_exists ( public_path ( 'images/achatpacks' ) ) ) { mkdir ( public_path ( 'images/achatpacks' ) ) ; } $ file -> move ( public_path ( 'images/achatpacks' ) , $ video ) ; $ achatpack -> video = " images/achatpacks/ " . $ video ; $ achatpack -> save ( ) ; } else if ( strstr ( $ mime , " image/ " ) ) { $ image = $ achatpack -> id . '.' . $ file -> getClientOriginalExtension ( ) ; if ( ! file_exists ( public_path ( 'images/achatpacks' ) ) ) { mkdir ( public_path ( 'images/achatpacks' ) ) ; } $ file -> move ( public_path ( 'images/achatpacks' ) , $ image ) ; $ achatpack -> image = " images/achatpacks/ " . $ image ; $ achatpack -> save ( ) ; } } return redirect ( ) -> route ( 'packpubs.index' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .