/** * Bootstrap the application services. * * @return void */ public function boot() { $this->app['validator']->extend('checkSecret', function ($attribute, $value, $parameters) { $c = \App\Collection::where('secret', $value)->first(); if ($c) { return true; } return false; }); }
private function addTournamentToDB($nimi, $aika, $secret, $pistelasku, $ratkaisuaika) { try { $collection = \App\Collection::where('secret', $secret)->firstOrFail(); } catch (ModelNotFoundException $e) { \Session::flash('errorMsg', 'Secret key not found!'); return \Redirect::back(); } $tournament = new \App\Tournament(); $key = $this->createNewSecret(); $tournament->key = $key; $tournament->name = $nimi; $tournament->starts_at = date('Y-m-d H:i:s', strtotime($aika)); $tournament->pistelasku = $pistelasku; $tournament->ratkaisuaika = $ratkaisuaika; $tournament->loaded_to_server = 0; $tournament->collection_id = $collection->id; $tournament->save(); return $key; }
public function addbooks() { header('Content-Type: text/html; charset=utf-8'); for ($i = 0; $i <= 10; $i++) { $user = new User(); $user->name = $this->generateRandomString(5); $user->password = bcrypt($user->name); $user->email = $user->name . '@gmail.com'; $user->save(); } $names = ['%22feliz%20gouveia%22', '%22nuno%20ribeiro%22', '%22jose%20torres%22', '%22borges%20gouveia%22', '%22Sophia%20breyner%22', '%22Fernando%20Pessoa%22', '%22Eça%20De%20Queiros%22']; foreach ($names as $name) { $content = file_get_contents('https://www.googleapis.com/books/v1/volumes?q=' . $name); $content = json_decode($content, true); $auts = Author::all('name'); $authors = array(); foreach ($auts as $aut) { $authors[] = $aut['name']; } $pubs = Publisher::all('publisher'); $publishers = array(); foreach ($pubs as $pub) { $publishers[] = $pub['publisher']; } $cats = Collection::all('collection'); $categories = array(); foreach ($cats as $cat) { $categories[] = $cat['collection']; } foreach ($content['items'] as $data) { $data = $data['volumeInfo']; $book = new Book(); if (isset($data['title'])) { $book->title = $data['title']; } if (isset($data['subtitle'])) { $book->subtitle = $data['subtitle']; } if (isset($data['publishedDate'])) { $book->publishedDate = $data['publishedDate']; } if (isset($data['description'])) { $book->description = $data['description']; } if (isset($data['pageCount'])) { $book->pages = $data['pageCount']; } if (isset($data['language'])) { $book->language = $data['language']; } if (isset($data['industryIdentifiers'])) { foreach ($data['industryIdentifiers'] as $value) { if ($value['type'] == 'ISBN_13') { $book->isbn13 = $value['identifier']; } if ($value['type'] == 'ISBN_10') { $book->isbn10 = $value['identifier']; } } } if (isset($data['publisher'])) { if (!in_array($data['publisher'], $publishers)) { $publishers[] = $data['publisher']; $publisher = new Publisher(); $publisher->publisher = $data['publisher']; $publisher->save(); $publisher_id = $publisher->id; } else { $publisher = Publisher::where('publisher', '=', $data['publisher'])->limit(1)->get(); $publisher_id = $publisher[0]->id; } } if (isset($data['imageLinks']['thumbnail'])) { $book->cover = file_get_contents($data['imageLinks']['thumbnail']); } $book->price_day = random_int(0, 15); $book->price_bail = random_int(10, 50); $book->price_sale = random_int(10, 79); $books[] = $book; $book->id_publisher = $publisher_id; $book->id_user = rand(1, 10); $book->save(); $book_id = $book->id; if (isset($data['categories'])) { foreach ($data['categories'] as $value) { if (!in_array($value, $categories)) { $categories[] = $value; $category = new Collection(); $category->collection = $value; $category->save(); $category_id = $category->id; $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category_id; $collections->save(); } else { $category = Collection::where('collection', '=', $value)->limit(1)->get(); $collections = new Book_Collection(); $collections->book_id = $book_id; $collections->collection_id = $category[0]->id; $collections->save(); } } } if (isset($data['authors'])) { foreach ($data['authors'] as $value) { if (!in_array($value, $authors)) { $authors[] = $value; $author = new Author(); $author->name = $value; $author->save(); $author_id = $author->id; $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author_id; $author_book->save(); } else { $author = Author::where('name', 'like', $value)->limit(1)->get(); $author_book = new Author_Book(); $author_book->book_id = $book_id; $author_book->author_id = $author[0]->id; $author_book->save(); } } } # code... } } }
/** * Toggle tattoo collect * * @return View */ public function collect(Request $request) { $res = array(); $res['success'] = false; $tattooId = $request->input('id'); $user = Auth::user(); if ($user->collections()->where('tattoo_id', $tattooId)->count()) { $collection = Collection::where('tattoo_id', $tattooId)->where('user_id', $user->id)->first(); if ($collection) { //already collected so uncollect now(delete) $collection->delete(); $res['data'] = 'Collect'; //uncollect success now show Collect $res['success'] = true; $res['collectCount'] = Collection::where('tattoo_id', $tattooId)->count(); } } else { $collection = new Collection(); $collection->tattoo_id = $tattooId; $collection->user_id = $user->id; if ($collection->save()) { $res['data'] = 'Uncollect'; //collect success now show Uncollect $res['success'] = true; $res['collectCount'] = Collection::where('tattoo_id', $tattooId)->count(); } } return $res; }
public function search($name) { $collection = Collection::where('name', 'LIKE', '%' . $name . '%')->get(); return response()->json(['collections' => $collection]); }
public function getUnapprovedCollection() { $collections = Collection::where('approved', '=', False)->get(); $collections = $collections->filter(function ($collection) { return $collection->hasThree(); }); // return $collections; // $collections = $collections->paginate(); return view('admin.unapprovedCollections')->with('collections', $collections); }
public function search($name) { $products = Product::where('name', 'LIKE', '%' . $name . '%')->get(); // $products = Product::add_created_by_and_category($products); $collection = Collection::where('name', 'LIKE', '%' . $name . '%')->get(); // return response()->json(['collections' => $collection]); return response()->json(['products' => $products, 'collections' => $collection]); }
private function createNewSecret($times = 0) { if ($times > 5) { return \App::abort(403, 'Could not create secret key - contact administrator'); } $chars = "qwertyuipasdfghjklzxcvbnm12345678900"; $secret = ""; for ($i = 0; $i < 5; $i++) { $r = rand(0, strlen($chars) - 1); $secret .= $chars[$r]; } if (\App\Collection::where('secret', $secret)->first()) { return $this->createNewSecret($times + 1); } return $secret; }