app/Http/Controllers/ServiceController.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)
    {
        try{
            $validator = $request->validate([ 
                'titre' => 'required|string|unique:services|max:255',
                'description' =>'required|string',
                'prix' =>'numeric|nullable', 
                'photo'=>'mimes:jpeg,bmp,png,jpg,svg|image|filled|max:2500',
            ] ); 
            $service = new Service();
            $service->titre = $request->input('titre');
            $service->description = $request->input('description');
            $service->prix = $request->input('prix'); 
            if($request->hasFile('photo')){ 
            $image =  $request->file('photo')->getClientOriginalName();
            $service->photo = $request->file('photo')->storeAs('services',$image);
            }
            $service->save();
            return redirect('services')->with('success', 'Le service a été ajouté avec succès!'); 
        }catch (Exception $e) {
            return redirect('services')->with('error', $e->getMessage());
        }
    }
public function store ( Request $ request ) { try { $ validator = $ request -> validate ( [ 'titre' => 'required|string|unique:services|max:255' , 'description' => 'required|string' , 'prix' => 'numeric|nullable' , 'photo' => 'mimes:jpeg,bmp,png,jpg,svg|image|filled|max:2500' , ] ) ; $ service = new Service ( ) ; $ service -> titre = $ request -> input ( 'titre' ) ; $ service -> description = $ request -> input ( 'description' ) ; $ service -> prix = $ request -> input ( 'prix' ) ; if ( $ request -> hasFile ( 'photo' ) ) { $ image = $ request -> file ( 'photo' ) -> getClientOriginalName ( ) ; $ service -> photo = $ request -> file ( 'photo' ) -> storeAs ( 'services' , $ image ) ; } $ service -> save ( ) ; return redirect ( 'services' ) -> with ( 'success' , 'Le service a été ajouté avec succès!');  } catch ( Exception $ e ) { return redirect ( 'services' ) -> with ( 'error' , $ e -> getMessage ( ) ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .