app/Http/Controllers/Admin/PackagesController.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)
    {
        $validator = Validator::make($request->all(), [
            'name'              => ['required', 'string'],
            'hours'             => ['required', 'string'],
            'prepaid'           => ['required', 'integer'],
            'student'           => ['nullable', 'integer'],
            'grades'            => ['required', 'Array'],
            'description'       => ['required', 'string'],
            'price_canada'      => ['required', 'string'],
            'price_usa'         => ['required', 'string'],
            'price_others'      => ['required', 'string'],
            'status'            => ['required', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect(route('admin.users.assignments.create'));
        }
        $data = $request->all();
        $package = Package::create([
            'name'              => $data['name'],
            'prepaid'           => $data['prepaid'],
            'student_id'        => $data['student'],
            'description'       => $data['description'],
            'price_can'         => $data['price_canada'],
            'price_usa'         => $data['price_usa'],
            'price_alb'         => $data['price_others'],
            'hours'             => $data['hours'],
            'status'            => $data['status']
        ]);
        if ($package == NULL)
        {
            $request->session()->flash('error', "There was an error creating the package");
            return redirect(route('admin.packages.create'));
        }
        foreach ($data['grades'] as $grade)
        {
            $package->grades()->attach($grade);
        }
        $package->save();
        $request->session()->flash('success', "The Package has been created successfully");
        $packages = Package::all();
        return view('admin.packages.index')->with('packages', $packages);
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'name' => [ 'required' , 'string' ] , 'hours' => [ 'required' , 'string' ] , 'prepaid' => [ 'required' , 'integer' ] , 'student' => [ 'nullable' , 'integer' ] , 'grades' => [ 'required' , 'Array' ] , 'description' => [ 'required' , 'string' ] , 'price_canada' => [ 'required' , 'string' ] , 'price_usa' => [ 'required' , 'string' ] , 'price_others' => [ 'required' , 'string' ] , 'status' => [ 'required' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( route ( 'admin.users.assignments.create' ) ) ; } $ data = $ request -> all ( ) ; $ package = Package :: create ( [ 'name' => $ data [ 'name' ] , 'prepaid' => $ data [ 'prepaid' ] , 'student_id' => $ data [ 'student' ] , 'description' => $ data [ 'description' ] , 'price_can' => $ data [ 'price_canada' ] , 'price_usa' => $ data [ 'price_usa' ] , 'price_alb' => $ data [ 'price_others' ] , 'hours' => $ data [ 'hours' ] , 'status' => $ data [ 'status' ] ] ) ; if ( $ package == NULL ) { $ request -> session ( ) -> flash ( 'error' , " There was an error creating the package " ) ; return redirect ( route ( 'admin.packages.create' ) ) ; } foreach ( $ data [ 'grades' ] as $ grade ) { $ package -> grades ( ) -> attach ( $ grade ) ; } $ package -> save ( ) ; $ request -> session ( ) -> flash ( 'success' , " The Package has been created successfully " ) ; $ packages = Package :: all ( ) ; return view ( 'admin.packages.index' ) -> with ( 'packages' , $ packages ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .