app/Http/Controllers/AdController.php
/**
     * Store a newly created ad in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
Store a newly created ad in storage.
Store a newly created ad in storage .
public function store(Request $request)
    {
        $request->validate([
            'title' => 'required',
            'description' => 'required',
            'license_plate' => 'required',
            'brand' => 'required',
            'doors' => 'required|numeric',
            'manufacture_year' => 'required|numeric',
            'apk_expiry_year' => 'digits:4',
            'apk_expiry_month' => 'digits:2',
            'apk_expiry_day' => 'digits:2',
            'price' => 'required|numeric',
            'mileage' => 'required|numeric',
            'photos' => 'required',
            'fuel_type_id' => 'required|numeric',
            'transmission_type_id' => 'required|numeric'
        ]);
        $ad = Ad::create($request->all());
        foreach ($request->photos as $photo) {
            $filename = $photo->store('photos', ['disk' => 'public']);
            Image::create([
                'ad_id' => $ad->id,
                'filename' => $filename
            ]);
        }
        return redirect()->route('ads.index')
            ->with('success', 'Advertentie succesvol aangemaakt!');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'title' => 'required' , 'description' => 'required' , 'license_plate' => 'required' , 'brand' => 'required' , 'doors' => 'required|numeric' , 'manufacture_year' => 'required|numeric' , 'apk_expiry_year' => 'digits:4' , 'apk_expiry_month' => 'digits:2' , 'apk_expiry_day' => 'digits:2' , 'price' => 'required|numeric' , 'mileage' => 'required|numeric' , 'photos' => 'required' , 'fuel_type_id' => 'required|numeric' , 'transmission_type_id' => 'required|numeric' ] ) ; $ ad = Ad :: create ( $ request -> all ( ) ) ; foreach ( $ request -> photos as $ photo ) { $ filename = $ photo -> store ( 'photos' , [ 'disk' => 'public' ] ) ; Image :: create ( [ 'ad_id' => $ ad -> id , 'filename' => $ filename ] ) ; } return redirect ( ) -> route ( 'ads.index' ) -> with ( 'success' , 'Advertentie succesvol aangemaakt!' ) ; }
Store a newly created ad in storage.
Store a newly created ad in storage .