本文整理汇总了PHP中Product::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::find方法的具体用法?PHP Product::find怎么用?PHP Product::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$product = Product::find($id);
$product->delete();
Session::flash('message', 'successfully deleted the product!');
return Redirect::to('products');
}
示例2: post_delete
public function post_delete()
{
$product = Product::find(Input::get('id'));
$product->categories()->delete();
$product->delete();
return Redirect::back()->with('flash', true)->with('flash_type', 'success')->with('flash_msg', 'Product deleted successfully.');
}
示例3: indexAction
public function indexAction()
{
$this->view->products = Product::find();
if ($this->session->get("auth")) {
$this->view->user = User::findFirst($this->session->get("auth")['id']);
}
}
示例4: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
// get the nerd
$item = Product::find($id);
// show the view and pass the nerd to it
return View::make('product.show')->with('item', $item);
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
$product = Product::find($id);
$res = array();
return Response::json($product);
}
示例6: getSearch
public static function getSearch($input = array())
{
$result = Product::where(function ($query) use($input) {
if (!empty($input['category_id'])) {
$query = $query->where('category_id', $input['category_id']);
}
if (!empty($input['type_id'])) {
$query = $query->where('type_id', $input['type_id']);
}
if (!empty($input['price_id'])) {
$query = $query->where('price_id', $input['price_id']);
}
if (!empty($input['time_id'])) {
$inputDate = getTime($input['time_id']);
$query = $query->where('start_time', '>=', $inputDate);
}
if (!empty($input['city_id'])) {
$query = $query->where('city_id', $input['city_id']);
}
if (!empty($input['city'])) {
$query = $query->where('city', $input['city']);
}
if (!empty($input['name'])) {
$query = $query->where('name', 'like', '%' . $input['name'] . '%');
}
//lat long
$query = $query->where('status', ACTIVE);
})->select(listFieldProduct())->get();
foreach ($result as $key => $value) {
$value->avatar = url(PRODUCT_UPLOAD . '/' . $value->user_id . '/' . Product::find($value->id)->avatar);
$value->block = Common::checkBlackList(Input::get('user_id'), $value->user_id);
}
return $result;
}
示例7: addCart
public function addCart($id)
{
$product = Product::find($id);
$quantity = Input::get('qt');
$name = $product->name;
if (intval($quantity) > $product->stock) {
return Redirect::to('product/' . $id)->with('message', 'La quantité du stock est insufisante pour votre commande');
}
if (Session::has('cart')) {
$carts = Session::get('cart', []);
foreach ($carts as &$item) {
if ($item['name'] == $name) {
$item["quantity"] += intval($quantity);
Session::set('cart', $carts);
return Redirect::to('product/' . $id)->with('message', 'Votre panier a été mis à jour');
}
}
}
$new_item = array();
$new_item['name'] = $name;
$new_item['price'] = $product->price;
$new_item['quantity'] = intval($quantity);
$new_item['description'] = $product->description;
$new_item['picture'] = $product->picture;
Session::push('cart', $new_item);
return Redirect::to('product/' . $id)->with('message', 'Le produit a été ajouté à votre panier');
}
示例8: postAddtocart
public function postAddtocart()
{
$product = Product::find(Input::get('id'));
$quantity = Input::get('quantity');
Cart::insert(array('id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image));
return Redirect::to('store/cart');
}
示例9: showCart
public function showCart()
{
$session_items = $cart_items = [];
if (Session::has('cart') && !empty(Session::get('cart'))) {
$session_items = Session::get('cart');
foreach ($session_items as $item) {
$unserialized_item = unserialize($item);
$product = Product::find($unserialized_item->productId);
$cart_item = new StdClass();
$cart_item->p_id = $product->id;
$cart_item->name = $product->name;
$cart_item->image = $product->image;
$cart_item->price = $product->price;
$cart_item->qtt = $unserialized_item->qtt;
$cart_item->total = $cart_item->price * $cart_item->qtt;
$counter = 0;
$found = false;
$index = null;
foreach ($cart_items as $it) {
if ($it->p_id == $product->id) {
$index = $counter;
$found = true;
}
$counter++;
}
if ($found) {
$cart_items[$index]->qtt = $cart_items[$index]->qtt + $cart_item->qtt;
$cart_items[$index]->total = $cart_items[$index]->qtt * $cart_item->price;
} else {
$cart_items[] = $cart_item;
}
}
}
return View::make('cart', compact('cart_items'));
}
示例10: find
/**
* Find a model by its primary key.
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Support\Collection|static
*/
public function find($id)
{
$model = Product::find($id);
if ($model) {
return $model;
}
throw new ResourceNotFoundException('Product was not found.');
}
示例11: postAddtocart
public function postAddtocart()
{
$product = Product::find(Input::get('id'));
$quantity = Input::get('quantity');
$member_id = Auth::user()->id;
Cart::create(array('product_id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image, 'member_id' => $member_id));
return Redirect::to('store/cart');
}
示例12: show
public function show()
{
if (!isset($_GET['id'])) {
return call('pages', 'error');
}
$product = Product::find($_GET['id']);
require_once 'views/products/show.php';
}
示例13: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 50) as $index) {
$number = rand(1, 5);
$product = Product::find($number);
Record::create(["name" => $product->name, "action" => "trials", "status" => "comes_in", "authorization" => $faker->firstNameFemale, "amount" => 5 + $index * 5, "product_id" => $number]);
}
}
示例14: indexAction
public function indexAction()
{
// set title page
Tag::setTitle("Home");
$behandeling = Behandeling::find();
$product = Product::find();
$this->view->setVar('behandeling', $behandeling);
$this->view->setVar('product', $product);
}
示例15: it_should_upload_single_media
/** @test */
public function it_should_upload_single_media()
{
config()->set('medias.models', ['products' => ['model' => 'Product', 'fields' => ['cover']]]);
$product = new Product();
$product->id = 1;
$product->uploadSingleMedia($this->getPicture(), 'cover');
$product->save();
$this->assertNotNull(Product::find(1)->cover);
}