Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'required|min:5|unique:branches', 'email' => 'required|min:5|unique:branches', 'city' => 'required', 'phone' => 'required']);
     if ($validator->fails()) {
         if ($request->ajax()) {
             return response()->json($validator->messages());
         } else {
             return \Redirect::back()->withErrors($validator)->withInput();
         }
     }
     array_forget($request, "_token");
     $all_request = $request->all();
     $branch = new Branch();
     foreach ($all_request as $key => $value) {
         $branch->{$key} = $value;
     }
     if ($request->ajax()) {
         if ($branch->save()) {
             return response()->json("Site Successfully Created");
         } else {
             return response()->json("Unexpected Error Record Could not be saved");
         }
     } else {
         //if post  is not AJAX
         if ($branch->save()) {
             \Session::flash("success_message", "Site Successfully Created");
             return Redirect::back();
         } else {
             \Session::flash("error_message", "Unexpected Error Role was not created");
             return Redirect::back();
         }
     }
 }
Пример #2
0
 public static function addNew(Request $request)
 {
     $branch = new Branch();
     $branch->name = $request->input('name');
     $branch->phone = $request->input('phone');
     $branch->fax = $request->input('fax');
     $branch->email = $request->input('email');
     $branch->save();
     return $branch;
 }
Пример #3
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     $data = $request->only('branchName', 'branchLocation');
     //return $data;
     $branch = new Branch();
     $branch->name = $data['branchName'];
     $branch->location = $data['branchLocation'];
     $branch->delivery_charge = $request['delivery_charge'];
     if ($branch->save()) {
         $returnData = array('status' => 'ok', 'message' => 'Branch created', 'branch' => $branch, 'code' => 200);
         return Response::json($returnData, 200);
     } else {
         $returnData = array('status' => 'fail', 'message' => 'Branch not created', 'code' => 500);
         return Response::json($returnData, 200);
     }
 }
Пример #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $validator = \Validator::make($request->all(), ['name' => 'required', 'city' => 'required']);
     if ($validator->fails()) {
         return response()->json(array('status' => 500, 'monolog' => array('title' => 'errors', 'message' => implode($validator->errors()->all(), '<br>'))));
     }
     $branch = new Branch();
     $branch->name = $request->name;
     // find province, country
     $city = \App\City::where('city_name', $request->city)->first();
     $branch->city = $request->city;
     $branch->province = $city->province->province_name;
     $branch->country = $city->province->country->nicename;
     $branch->manager = $request->manager;
     $branch->save();
     return response()->json(array('status' => 200, 'monolog' => array('title' => 'success', 'message' => 'object has been saved')));
 }
Пример #5
0
 public static function AddGradesAndLevels($user_id, $school_year_id)
 {
     $admin = User::where('id', $user_id)->where('type', 'ecole')->first();
     if ($admin) {
         $creche = new Grade();
         $creche->name = 'Crèche';
         $creche->user_id = $user_id;
         $creche->school_year_id = $school_year_id;
         $creche->save();
         if ($creche->id) {
             $niveau = new Level();
             $niveau->niveau = 'Crèche';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $creche->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
         }
         $mater = new Grade();
         $mater->name = 'Maternelle';
         $mater->user_id = $user_id;
         $mater->school_year_id = $school_year_id;
         $mater->save();
         if ($mater) {
             $niveau = new Level();
             $niveau->niveau = 'Petite Section';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $mater->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
             $niveau = new Level();
             $niveau->niveau = 'Moyenne Section';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $mater->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
             $niveau = new Level();
             $niveau->niveau = 'Grande Section';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $mater->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
         }
         $sc = new Grade();
         $sc->name = 'Primaire';
         $sc->user_id = $user_id;
         $sc->school_year_id = $school_year_id;
         $sc->save();
         if ($sc) {
             for ($i = 1; $i <= 6; $i++) {
                 $niveau = new Level();
                 $niveau->niveau = 'CE' . $i;
                 $niveau->user_id = $user_id;
                 $niveau->grade_id = $sc->id;
                 $niveau->school_year_id = $school_year_id;
                 $niveau->save();
             }
         }
         $col = new Grade();
         $col->name = 'Collège';
         $col->user_id = $user_id;
         $col->school_year_id = $school_year_id;
         $col->save();
         if ($col) {
             for ($i = 1; $i <= 3; $i++) {
                 if ($i == 1) {
                     $niveau = new Level();
                     $niveau->niveau = '1ère année Collège';
                     $niveau->user_id = $user_id;
                     $niveau->grade_id = $col->id;
                     $niveau->school_year_id = $school_year_id;
                     $niveau->save();
                 } elseif ($i > 1) {
                     $niveau = new Level();
                     $niveau->niveau = $i . 'ème année Collège';
                     $niveau->user_id = $user_id;
                     $niveau->grade_id = $col->id;
                     $niveau->school_year_id = $school_year_id;
                     $niveau->save();
                 }
             }
         }
         $lyc = new Grade();
         $lyc->name = 'Lycée';
         $lyc->user_id = $user_id;
         $lyc->school_year_id = $school_year_id;
         $lyc->save();
         if ($lyc) {
             $niveau = new Level();
             $niveau->niveau = 'Tronc Commun';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $lyc->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
             if ($niveau->id) {
                 $l = Level::where('id', $niveau->id)->where('user_id', $user_id)->first();
                 $branchesTc = ['Tronc Commun Sciences', 'Tronc Commun Lettres et sciences humaines', 'Tronc Commun Technologique', 'Tronc Commun Enseignement Originel'];
                 foreach ($branchesTc as $br) {
                     $branche = new Branch();
                     $branche->nom_branche = $br;
                     $branche->code_branche = "";
                     $branche->user_id = $user_id;
                     $branche->level_id = $niveau->id;
                     $branche->school_year_id = $school_year_id;
                     $branche->save();
                     if ($branche->id) {
                         $l->onbranches()->attach([$branche->id]);
                     }
                 }
             }
             $niveau = new Level();
             $niveau->niveau = '1ère Baccalauréat';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $lyc->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
             if ($niveau->id) {
                 $l = Level::where('id', $niveau->id)->where('user_id', $user_id)->first();
                 $branches1Bac = ['Sciences mathématiques', 'Sciences expérimentales', 'Bac Sciences et Technologies Electriques', 'Bac Sciences et Technologies Mecaniques', 'Arts appliqués', 'Sciences économiques et gestion', 'Lettres et sciences humaines', 'Langue Arabe', 'Sciences de la Chariaa'];
                 foreach ($branches1Bac as $br) {
                     $branche = new Branch();
                     $branche->nom_branche = $br;
                     $branche->code_branche = "";
                     $branche->user_id = $user_id;
                     $branche->level_id = $niveau->id;
                     $branche->school_year_id = $school_year_id;
                     $branche->save();
                     if ($branche->id) {
                         $l->onbranches()->attach([$branche->id]);
                     }
                 }
             }
             $niveau = new Level();
             $niveau->niveau = 'Baccalaureat';
             $niveau->user_id = $user_id;
             $niveau->grade_id = $lyc->id;
             $niveau->school_year_id = $school_year_id;
             $niveau->save();
             if ($niveau->id) {
                 $l = Level::where('id', $niveau->id)->where('user_id', $user_id)->first();
                 $branchesBac = ['Bac Sciences mathématiques A', 'Bac Sciences Mathématiques B', 'Bac Sciences Physiques', 'SVT Bac', 'Bac Sciences Agronomiques', 'Bac Sciences et Technologies Electriques', 'Bac Sciences et Technologies Mecaniques', 'Arts appliqués', 'Bac Sciences économiques', 'Bac Techniques de gestion et comptabilité', 'Bac Lettres', 'Sciences humaines', 'Langue Arabe', 'Sciences de la Chariaa'];
                 foreach ($branchesBac as $br) {
                     $branche = new Branch();
                     $branche->nom_branche = $br;
                     $branche->code_branche = "";
                     $branche->user_id = $user_id;
                     $branche->level_id = $niveau->id;
                     $branche->school_year_id = $school_year_id;
                     $branche->save();
                     if ($branche->id) {
                         $l->onbranches()->attach([$branche->id]);
                     }
                 }
             }
         }
     }
 }