Пример #1
0
 public function show($collectionSlug, $materialSlug)
 {
     $material = Material::with(['collection' => function ($query) use($collectionSlug) {
         $query->whereSlug($collectionSlug)->firstOrFail();
     }])->whereSlug($materialSlug)->firstOrFail();
     return view('pages.materials.show', compact('material'));
 }
 public function getFilter($request)
 {
     $query = Material::with('categories', 'levels', 'languageFocuses', 'activityUses', 'pupilTasks', 'book');
     //names of eager
     if (trim($request->book) !== '') {
         $query = $query->whereHas('book', function ($bookQuery) use($request) {
             $bookQuery->where('book', $request->book);
         });
     }
     if ($request->level) {
         for ($i = 0; $i < count($request->level); $i++) {
             $query = $query->whereHas('levels', function ($levelQuery) use($request, $i) {
                 $levelQuery->where('level', $request->level[$i]);
             });
         }
     }
     if ($request->category_list) {
         for ($i = 0; $i < count($request->category_list); $i++) {
             $query = $query->whereHas('categories', function ($categoryQuery) use($request, $i) {
                 $categoryQuery->where('category', $request->category_list[$i]);
             });
         }
     }
     if ($request->language_focus) {
         for ($i = 0; $i < count($request->language_focus); $i++) {
             $query = $query->whereHas('languageFocuses', function ($focusQuery) use($request, $i) {
                 $focusQuery->where('language_focus', $request->language_focus[$i]);
             });
         }
     }
     if ($request->activity_use) {
         for ($i = 0; $i < count($request->activity_use); $i++) {
             $query = $query->whereHas('activityUses', function ($activityQuery) use($request, $i) {
                 $activityQuery->where('activity_use', $request->activity_use[$i]);
             });
         }
     }
     if ($request->pupil_task) {
         for ($i = 0; $i < count($request->pupil_task); $i++) {
             $query = $query->whereHas('pupilTasks', function ($pupilQuery) use($request, $i) {
                 $pupilQuery->where('pupil_task', $request->pupil_task[$i]);
             });
         }
     }
     if ($request->time_needed_class) {
         $class = explode(',', $request->time_needed_class);
         $query = $query->whereBetween('time_needed_class', $class);
     }
     if ($request->time_needed_prep) {
         $prep = explode(',', $request->time_needed_prep);
         $query = $query->whereBetween('time_needed_prep', $prep);
     }
     return $query->get();
     // make the query and load the data
 }
Пример #3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $materials = Material::with('unit')->orderBy('name', 'asc')->get();
     return $materials;
 }