app/Http/Controllers/Achat.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)
    {
        $dispo = $request->input('disponibilite');
        if(!$dispo){
            $dispo = now();
        }
        $annonce = Annonce::create([
            'user_id'=> 1,
            'fichier_id'=> 1,
            'titre'=> $request->input('titre'),
            'description'=> $request->input('description'),
            'date_pub'=> $request->input('date_pub'),
            'cout'=> $request->input('cout'),
            'quantite'=> $request->input('quantite'),
            'disponibilite'=> $dispo,
            'statut_ann'=> 0,
        ]);
        if ($annonce) {
            return redirect()->route('annonces.show', $annonce->id);
        }
    }
public function store ( Request $ request ) { $ dispo = $ request -> input ( 'disponibilite' ) ; if ( ! $ dispo ) { $ dispo = now ( ) ; } $ annonce = Annonce :: create ( [ 'user_id' => 1 , 'fichier_id' => 1 , 'titre' => $ request -> input ( 'titre' ) , 'description' => $ request -> input ( 'description' ) , 'date_pub' => $ request -> input ( 'date_pub' ) , 'cout' => $ request -> input ( 'cout' ) , 'quantite' => $ request -> input ( 'quantite' ) , 'disponibilite' => $ dispo , 'statut_ann' => 0 , ] ) ; if ( $ annonce ) { return redirect ( ) -> route ( 'annonces.show' , $ annonce -> id ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//dd($request->all()); /*if($request['image'] != null){
                $file = $request->file('image');
                $image = $annonce->id.'.'.$file->getClientOriginalExtension();

                if (!file_exists(public_path('images/annonces'))) {
                    mkdir(public_path('images/annonces'));
                }
                $file->move(public_path('images/annonces'), $image);
                $annonce->image = "images/annonces/".$image;
                $annonce->save();
            }*/