app/Http/Controllers/ClientController.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)
    {
        $this->validate($request, [
            'name' => 'required|unique:clients,name',
        ]);
        try {
            DB::beginTransaction();
            $client = Client::create([
                'name' => $request->name,
                'tele' => $request->tele,
                'asrn'=>$request->asrn,
                'dateDubet'=>$request->dateD,
                'image' => 'image.jpg',
            ]);
            if($request->hasFile('image')){
                $image = $request->image;
                $image_new_name = time() . '.' . $image->getClientOriginalExtension();
                $image->move('storage/post/', $image_new_name);
                $client->image = '/storage/post/' . $image_new_name;
                $client->save();
            }
            $abonnement = Abonnement::create([
                'date_dubet' => $request->dateD,
                'date_fine' => DB::raw('DATE_ADD(date_dubet, INTERVAL 1 MONTH)'),
                'payment'=>$request->pay,
                'client_id'=>$client->id,
            ]);
            DB::commit();
        } catch (Exception $e) {
            DB::rollBack();
            return redirect()->back()->withErrors([
                $e->getMessage()
            ]);
        }
        $request->session()->flash('success', 'Client created successfully');
        return redirect()->back();
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'name' => 'required|unique:clients,name' , ] ) ; try { DB :: beginTransaction ( ) ; $ client = Client :: create ( [ 'name' => $ request -> name , 'tele' => $ request -> tele , 'asrn' => $ request -> asrn , 'dateDubet' => $ request -> dateD , 'image' => 'image.jpg' , ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ image = $ request -> image ; $ image_new_name = time ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( 'storage/post/' , $ image_new_name ) ; $ client -> image = '/storage/post/' . $ image_new_name ; $ client -> save ( ) ; } $ abonnement = Abonnement :: create ( [ 'date_dubet' => $ request -> dateD , 'date_fine' => DB :: raw ( 'DATE_ADD(date_dubet, INTERVAL 1 MONTH)' ) , 'payment' => $ request -> pay , 'client_id' => $ client -> id , ] ) ; DB :: commit ( ) ; } catch ( Exception $ e ) { DB :: rollBack ( ) ; return redirect ( ) -> back ( ) -> withErrors ( [ $ e -> getMessage ( ) ] ) ; } $ request -> session ( ) -> flash ( 'success' , 'Client created successfully' ) ; return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Session::flash('success', 'Category created successfully');