Exemple #1
0
 /**
  * Search resources by given $search.
  *
  * @param string $search
  * @param int $perPage
  * @return mixed
  */
 public function search($search, $perPage = 10)
 {
     return $this->article->where(function ($query) use($search) {
         $q = "%{$search}%";
         return $query->where('title', 'like', $q)->where('body', 'like', $q);
     })->paginate($perPage);
 }
Exemple #2
0
 public function setMain($id)
 {
     $image = Model::where('id', '=', $id)->firstOrFail();
     Model::where('post_id', '=', $image->post_id)->update(['main' => 0]);
     $article = Article::where('id', '=', $image->post_id)->firstOrFail();
     $image->main = 1;
     $image->save();
     $article->image = $image->url;
     $article->save();
 }