app/Http/Controllers/SalonsController.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)
    {
        $person = Personne::where('user_id', Auth::id())->get()->first();
        $salon = Salon::create([
            'libelle'      => $request->input('libelle'),
            'description'      => $request->input('description'),
            'structure_id'      => $person->structure_id,
            'dateSalon'         => $request->input('dateSalon'),
            'heureSalon'         => $request->input('heureSalon'),
            'heureFinSalon'         => $request->input('heureFinSalon'),
            'statutSalon'       => 0
        ]);
        if ($salon) {
            if($request['image'] != null){
                $file = $request->file('image');
                $image = $salon->id.'.'.$file->getClientOriginalExtension();
                if (!file_exists(public_path('images/salons'))) {
                    mkdir(public_path('images/salons'));
                }
                $file->move(public_path('images/salons'), $image);
                $salon->image = "images/salons/".$image;
                $salon->save();
            }
            ParticipeSalon::create([
                'user_id'       => Auth::id(),
                'salon_id'      => $salon->id,
                'moderateur'    => 0,
                'statut'        => 1
            ]);
            return redirect()->route("salons.show", $salon->id);
        }
    }
public function store ( Request $ request ) { $ person = Personne :: where ( 'user_id' , Auth :: id ( ) ) -> get ( ) -> first ( ) ; $ salon = Salon :: create ( [ 'libelle' => $ request -> input ( 'libelle' ) , 'description' => $ request -> input ( 'description' ) , 'structure_id' => $ person -> structure_id , 'dateSalon' => $ request -> input ( 'dateSalon' ) , 'heureSalon' => $ request -> input ( 'heureSalon' ) , 'heureFinSalon' => $ request -> input ( 'heureFinSalon' ) , 'statutSalon' => 0 ] ) ; if ( $ salon ) { if ( $ request [ 'image' ] != null ) { $ file = $ request -> file ( 'image' ) ; $ image = $ salon -> id . '.' . $ file -> getClientOriginalExtension ( ) ; if ( ! file_exists ( public_path ( 'images/salons' ) ) ) { mkdir ( public_path ( 'images/salons' ) ) ; } $ file -> move ( public_path ( 'images/salons' ) , $ image ) ; $ salon -> image = " images/salons/ " . $ image ; $ salon -> save ( ) ; } ParticipeSalon :: create ( [ 'user_id' => Auth :: id ( ) , 'salon_id' => $ salon -> id , 'moderateur' => 0 , 'statut' => 1 ] ) ; return redirect ( ) -> route ( " salons.show " , $ salon -> id ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .