本文整理汇总了PHP中app\Article::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::whereIn方法的具体用法?PHP Article::whereIn怎么用?PHP Article::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::whereIn方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($tag)
{
$rs = Tag::where('tag', $tag)->get();
$arr = array();
foreach ($rs as $v) {
array_push($arr, $v->article_id);
}
$articles = Article::whereIn('id', $arr)->get();
$tags = Tag::select('tag')->distinct()->get();
return view('member.tags.show', compact('tag', 'tags', 'articles'));
}
示例2: getArticles
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function getArticles($id, $number)
{
$category = Category::whereName($id)->first();
$sources = $category->sources;
$ids = [];
foreach ($sources as $source) {
$ids[] = $source->id;
}
$articles = Article::whereIn('source_id', $ids)->orderBy('date', 'DESC')->paginate($number);
return ['name' => $category->name, 'id' => $category->id, 'image_url' => $category->image_url, 'articles' => $articles->toArray()];
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$usr = Practicante::where('email', '=', $request->user()->email)->get();
$actual_rank = Tag::where('name', Config::get('constants.ranks')[$usr[0]->actual_rank])->get()[0]->id;
$withTags = DB::table('article_tag')->where('tag_id', $actual_rank)->get(array('article_id'));
//Cleaning the array
$justTags = array();
foreach ($withTags as $key => $value) {
array_push($justTags, $value->article_id);
}
$articles = Article::whereIn('id', $justTags)->get();
return View('practicante.tecnicas.index')->with('articles', $articles)->with('actual_rank', $usr[0]->actual_rank)->with('ranks', Config::get('constants.ranks'));
}
示例4: articlesTag
public function articlesTag($tag)
{
$withTags = DB::table('article_tag')->where('tag_id', $tag)->get(array('article_id'));
//Cleaning the array
$justTags = array();
foreach ($withTags as $key => $value) {
array_push($justTags, $value->article_id);
}
$articles = Article::whereIn('id', $justTags)->get();
if (count($articles) == 0) {
return response()->json(['error' => ['message' => 'No existen articulos con esta etiqueta']], 404);
}
return response()->json($articles, 200);
}
示例5: checkout
public function checkout(Request $request)
{
if (isset($_COOKIE['basket'])) {
$entries = $_COOKIE['basket'];
$entries = json_decode($entries);
} else {
return redirect('/');
}
$ids = array_pluck($entries, 'article_id');
$items = Article::whereIn('id', $ids)->get();
//->toArray();
$items = $items->keyBy('id');
$order = Order::create(['name' => $request->name, 'address' => $request->address, 'phone' => $request->phone]);
$summary = [];
$total_cost = 0;
foreach ($entries as $entry) {
OrdersToArticles::create(['article_id' => $entry->article_id, 'order_id' => $order->id, 'price' => $items->get($entry->article_id)->price, 'quantity' => $entry->amount]);
$summary[] = ['article_id' => $entry->article_id, 'title' => $items->get($entry->article_id)->title, 'price' => $items->get($entry->article_id)->price, 'amount' => $entry->amount];
$total_cost += end($summary)['price'] * end($summary)['amount'];
}
setcookie('basket', '', 0, '/');
//удаляем куки
return view('finish_order', ['order' => $order, 'entries' => $summary, 'total' => $total_cost]);
}
示例6: deleteArticle
public function deleteArticle()
{
$articles = Input::get('formarr', array());
Articlecontent::whereIn('article_id', $articles)->delete();
foreach ($articles as $article) {
Article::find($article)->menu_relations()->detach();
}
Article::whereIn('id', $articles)->delete();
return 1;
}
示例7: getFavoritesByModel
/**
* Return the favorites of a certain model or table, leave the data as is under $model->settings['favorites']
*
* @param $model
* @param $data
*
* @return object|false
*/
static function getFavoritesByModel($model, $data)
{
if (!isset($data[$model])) {
return false;
}
$data = array_keys($data[$model]);
switch ($model) {
case 'articles':
return Article::whereIn('id', $data)->get();
case 'sites':
return Site::whereIn('id', $data)->get();
case 'professions':
return Profession::whereIn('id', $data)->get();
case 'classifieds':
return Classified::whereIn('id', $data)->get();
case 'albums':
return Album::whereIn('id', $data)->get();
case 'agoda':
return AgodaHotel::whereIn('hotel_id', $data)->get();
default:
return false;
}
}
示例8: postBatch
/**
* batch update
* @param string $act
* @return json
*/
public function postBatch($act = 'update')
{
$result = false;
$ids = \Request::input('ids');
$idsArr = explode(',', $ids);
switch ($act) {
case 'delete':
$result = Article::whereIn('id', $idsArr)->delete();
break;
case 'update':
$key = \Request::input('key');
$value = \Request::input('value');
$tempData = $this->parseKey($key, $value);
$result = Article::whereIn('id', $idsArr)->update($tempData);
break;
}
$msg = [];
if ($result) {
$msg['status'] = 'success';
} else {
$msg['status'] = 'failed';
}
return response(json_encode($msg))->header('Content-Type', 'application/json');
}