本文整理汇总了PHP中app\Category::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::find方法的具体用法?PHP Category::find怎么用?PHP Category::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Category
的用法示例。
在下文中一共展示了Category::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: category
/**
* Show all products by category id.
*
* @param $id
* @return \Illuminate\View\View
*/
public function category($id)
{
$categories = $this->category->orderBy('name')->get();
$products = $this->product->where('category_id', '=', $id)->paginate(8);
$categoryName = $this->category->find($id)->name;
return view('ecomm.shop.partial.products-category', compact('categories', 'products', 'categoryName'));
}
示例2: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$job_id = $id;
$job_info = Job::find($job_id);
$job_category_info = JobCategory::where('job_id', '=', $job_id)->get();
$category_array = array();
foreach ($job_category_info as $a_job_category) {
$a_category_id = $a_job_category->category_id;
$a_category_value = Category::find($a_category_id)->kategori;
$category_array[count($category_array)] = $a_category_value;
}
$data['job_info'] = $job_info;
$data['category_array'] = $category_array;
// find out whether the logged-in user have already request this job (as a seeker)
// if the owner of this job is the logged-in user, then don't show the request button
$show_request_button = true;
$this_is_the_owner = false;
if (Auth::user() != null) {
$logged_user_id = Auth::user()->id;
if ($job_info->freelancer_info_id == $logged_user_id) {
// if the owner of this job is the logged-in user
$show_request_button = false;
$this_is_the_owner = true;
} else {
// if logged-in user already request this job (as a seeker)
if (JobRequest::find($job_id, $logged_user_id) != null) {
$show_request_button = false;
}
}
} else {
//if guest (not logged-in user)
}
return View::make('job.show')->with('data', $data)->with('jobs', $job_info)->with('job_id', $id)->with('show_request_button', $show_request_button)->with('this_is_the_owner', $this_is_the_owner);
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$category = Category::find($id);
$category->name = $request->name;
$category->save();
return redirect()->route('category.index');
}
示例4: browseCategory
/**
* Show user receipts of a specific Category.
*
* @param int $id
* @return Response
*/
public function browseCategory($id)
{
$receipts = Receipt::whereHas('categories', function ($query) use($id) {
$query->where('id', '=', $id);
})->where('user_id', '=', $this->user->id)->paginate();
return view('pages.receipts', compact('receipts'))->with('page_title', Category::find($id)->name);
}
示例5: deactivate
public function deactivate($id)
{
$category = Category::find($id);
$category->status = 0;
$category->save();
return redirect('home/categories');
}
示例6: showByUser
public function showByUser($user_id)
{
//directly copied pasted from list controller.
$list = Vote::where('user_id', '=', $user_id)->get();
$user_list = [];
foreach ($list as $pro) {
$product_id = $pro->product_id;
$product = Product::find($product_id);
if ($product != null) {
$created_by = $product['created_by'];
$category = Category::find($product['category_id']);
$category = $category['category'];
$user = User::find($created_by);
array_add($product, 'category', $category);
array_add($product, 'created_by_name', $user['name']);
$initial = explode(".", $product['image_url']);
$thumbFirst = "";
for ($i = 0; $i < sizeof($initial) - 1; $i++) {
$thumbFirst = $thumbFirst . $initial[$i];
}
$thumbnail = $thumbFirst . '-200x200.' . $initial[sizeof($initial) - 1];
array_add($product, 'thumbnail', $thumbnail);
array_push($user_list, $product);
}
}
return $user_list;
// return response()->json([
// 'upvotted'=>$user_list]
// );
}
示例7: categories
public function categories()
{
$view = Input::get('view');
if ($view == null) {
return redirect('/admin/categories?view=hierarchy');
}
$levels = ['Main Category', 'Subcategory', 'Post Sub Category'];
$types = ['main-categories', 'sub-categories', 'post-sub-categories'];
$views = ['Hierarchy', 'Type', 'All'];
$cats = Category::roots()->get();
$category = Input::get('category');
$_category = Category::find($category);
if ($view == 'type') {
$type = Input::get('type');
if ($type == null) {
$type = $types[0];
}
// array_keys() = get keys from value
// appends() = add 'get' variables (to url)
$cats = Category::whereDepth(array_keys($types, $type))->paginate(25)->appends(Input::except('page'));
} else {
if ($view == 'all') {
$cats = Category::paginate(25)->appends(Input::except('page'));
}
}
return view('admin.main')->with('category', $_category)->with('cats', $cats)->with('levels', $levels)->with('view', $view)->with('views', $views)->with('types', $types);
// only for 'type' view
}
示例8: store
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['name' => 'required|max:100', 'model' => 'max:100', 'category_id' => 'required|array', 'photo' => 'image|max:2048']);
if (!$validator->fails()) {
$categories_id = $request->input('category_id');
$catTitles = "";
// add title and comma for success message
foreach ($categories_id as $index => $id) {
$catTitles .= Category::find($id)->title;
if ($index + 1 != count($categories_id)) {
$catTitles .= ", ";
}
}
$product = Product::create(['name' => $request->input('name'), 'model' => $request->input('model')]);
$product->categories()->attach($categories_id);
if ($request->hasFile('photo')) {
$uploaded_photo = $request->file('photo');
$extension = $uploaded_photo->getClientOriginalExtension();
$filename = md5(time()) . '.' . $extension;
$destinationPath = public_path('img');
$uploaded_photo->move($destinationPath, $filename);
}
$product->photo = $filename;
$product->save();
return redirect('products')->with('successMsg', $request->input('name') . ' has been successfully created under : ' . $catTitles);
} else {
return redirect()->back()->withErrors($validator)->withInput();
}
}
示例9: index
public function index()
{
$updates = new Update();
$category = Category::find(4);
$now = Carbon::now();
return view('about.galleries.index', compact('updates', 'now', 'category'));
}
示例10: destroy
/**
* Destroy the given category.
*
* @param Request $request
* @param string $categoryId
* @return Response
*/
public function destroy(Request $request, $categoryId)
{
$category = Category::find($categoryId);
$this->authorize('destroy', $category);
$category->destroy($categoryId);
return redirect('/categories');
}
示例11: edit
public function edit($id, $extra = array())
{
$category = \App\Category::find($id);
$extra['parents'] = array_filter($this->getParents($category));
$extra['selectedParentId'] = $id;
return parent::edit($id, $extra);
}
示例12: razredi
public function razredi($id)
{
$category = Category::find($id);
$students = Student::where('category_id', '=', $category->id)->get();
//return $category;
return view('reports.razred')->with('category->id', $category->id)->with('students', $students)->with('category', $category);
}
示例13: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker\Factory::create();
// Topic
$topicCategorys = ['Talk', 'Party', 'Movie', 'Music', 'Goods', 'Sport', 'Game'];
foreach ($topicCategorys as $index => $category) {
Category::create(['name' => $category, 'type_id' => Category::TYPE_TOPIC]);
}
// children Topic
$topicCategorys = Category::where('type_id', '=', Category::TYPE_TOPIC)->lists('id')->toArray();
foreach (range(1, 20) as $index) {
$parentId = $faker->randomElement($topicCategorys);
$name = Category::find($parentId)->name;
Category::create(['name' => $name . $index, 'type_id' => Category::TYPE_TOPIC, 'parent_id' => $parentId]);
}
// Article
$articleCategorys = ['Hot News', 'BeiJing', 'China', 'America', 'England'];
foreach ($articleCategorys as $index => $category) {
Category::create(['name' => $category, 'type_id' => Category::TYPE_ARTICLE]);
}
// Blog
$blogCategorys = ['Uncategory', 'Log', 'Heavy'];
foreach ($blogCategorys as $index => $category) {
Category::create(['name' => $category, 'type_id' => Category::TYPE_BLOG]);
}
}
示例14: show_for_other_user
public function show_for_other_user($user_id)
{
$list = Lists::where('user_id', '=', $user_id)->get();
$user_list = [];
foreach ($list as $pro) {
$product_id = $pro->product_id;
$product = Product::find($product_id);
if ($product != null) {
$created_by = $product['created_by'];
$category = Category::find($product['category_id']);
$category = $category['category'];
$user = User::find($created_by);
array_add($product, 'category', $category);
array_add($product, 'created_by_name', $user['name']);
$initial = explode(".", $product['image_url']);
$thumbFirst = "";
for ($i = 0; $i < sizeof($initial) - 1; $i++) {
$thumbFirst = $thumbFirst . $initial[$i];
}
$thumbnail = $thumbFirst . '-130x90.' . $initial[sizeof($initial) - 1];
//thumb size changed
array_add($product, 'thumbnail', $thumbnail);
array_push($user_list, $product);
}
}
return response()->json(['list' => $user_list]);
}
示例15: updateCategory
public function updateCategory(Request $request, $id)
{
$Category = Category::find($id);
$Category->name = $request->input('name');
$Category->save();
return response()->json($Category);
}