public function index(Request $request)
 {
     $posts = Post::query()->orderBy('created_at', 'desc')->get()->all();
     foreach ($posts as $post) {
         $post->author = $post->getAuthor();
     }
     return view('dashboard.index', ['posts' => $posts]);
 }
 /**
  * Get All posts
  * @return array
  */
 public function findAll($author = null, $from = null, $to = null)
 {
     $query = Post::query();
     if ($author) {
         $query = $query->where('author', $author);
     }
     if ($from) {
         $query = $query->whereDate('date', '>=', new DateTime($from));
     }
     if ($to) {
         $query = $query->whereDate('date', '<=', new DateTime($to));
     }
     return $query->get();
 }
 public function search($input)
 {
     $query = Post::query();
     $columns = Schema::getColumnListing('posts');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
Beispiel #4
0
 public function image_bg_upload(Request $request)
 {
     $post = Post::query()->findOrFail($request->input('post_id'));
     $img = $post->id . "-bg." . $request->file('image-bg')->getClientOriginalExtension();
     $post->image = "upload/{$img}";
     $post->save();
     $request->file('image-bg')->move(public_path('img') . '/upload', $img);
     return "{ }";
 }