Example #1
0
 function _postFeaturEImageSource(Post $post)
 {
     if ($post->featureImage()) {
         return $post->featureImage();
     }
     return false;
 }
 public function category(Request $request)
 {
     $lastSegment = preg_split("/\\//", $request->url());
     $categorySlug = array_pop($lastSegment);
     // get the last segment on the current url
     $category = Tag::where('slug', $categorySlug)->first();
     // check if there is no category found.
     if (!$category) {
         return redirect()->route('front.error-404');
     }
     // condition where clause for parent categories or child.
     if ($category->parent_id == 0) {
         $field = 'tags.parent_id';
         $value = $category->id;
     } else {
         $field = 'tags.slug';
         $value = $category->slug;
     }
     // Get posts by PostTag slug or parent_id field
     $properties = Post::join('post_tags', 'posts.id', '=', 'post_tags.post_id')->join('tags', 'post_tags.tag_id', '=', 'tags.id')->where($field, $value)->select('posts.*', 'tags.name as tagName')->paginate(config('front.postPerPage'));
     $pageTitle = 'Category: ' . $category->name;
     if ($category->parent_id == 0) {
         $breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category') . '/' . $category->slug, 'name' => $category->name]];
     } else {
         $breadcrumbData = [['url' => url(), 'name' => 'Home'], ['url' => route('front.category', $category->parent()->slug), 'name' => $category->parent()->name], ['url' => route('front.category') . '/' . $category->parent()->slug . '/' . $category->slug, 'name' => $category->name]];
     }
     return view('properties', compact('properties', 'pageTitle', 'breadcrumbData'));
 }
 public function edit($id)
 {
     $post = Post::where('post_type', 'post')->where('id', $id)->first();
     if (!isset($post->id)) {
         $post = new Post();
     }
     return view('user.property-create', compact('post'));
 }
Example #4
0
 public function edit($id)
 {
     $post = Post::where('post_type', 'post')->where('id', $id)->first();
     if (!isset($post->id)) {
         $post = new Post();
     }
     return view('cms::post.post', compact('post'));
 }
Example #5
0
 public function addImage($postId, $fileMediaId)
 {
     $file = FileMedia::find($fileMediaId);
     $post = Post::find($postId);
     $post->feature_image = $file->filename;
     $post->save();
     return $post;
 }
Example #6
0
 public static function savePost(Request $request, Post $post = null)
 {
     if (!$post) {
         $post = new Post();
     }
     $isVisible = $request->get('is_visible');
     $post->title = $request->get('title');
     $post->user_id = Auth::id();
     $post->post_type = $request->get('post_type');
     $post->content = $request->get('content');
     $post->slug = str_slug($request->get('title'));
     $post->meta_keywords = $request->get('title');
     $post->meta_description = $request->get('content');
     $post->is_visible = isset($isVisible);
     if ($request->get('published_at')) {
         $post->published_at = $request->get('published_at') . ' ' . date("H:i:s", time());
     }
     $post->save();
     return $post;
 }
 public function searchAdvance(Request $request)
 {
     $country = $request->get('country');
     $location = $request->get('location');
     $type = $request->get('type');
     $minPrice = $request->get('min_price');
     $maxPrice = $request->get('max_price');
     $properties = Post::join('postmeta', function ($join) use($country, $location) {
         $join->on('posts.id', '=', 'postmeta.post_id')->where('postmeta.meta_value', '=', $country);
     })->select('posts.*', 'postmeta.meta_key', 'postmeta.meta_value')->paginate(config('front.postPerPage'));
     //TODO: some more work to do especially for type, minimum price and maximum price.
     $pageTitle = 'Advance Search Result';
     return view('properties', compact('properties', 'pageTitle'));
 }
Example #8
0
 public function handle()
 {
     $post = Post::where('slug', $this->slug)->first();
     if (!$post) {
         return redirect()->route('front.error-404');
     }
     $postTagIds = array();
     if (count($post->postTags) > 0) {
         foreach ($post->postTags as $postTag) {
             $postTagIds[] = $postTag->tag_id;
         }
     }
     // Retrieve related posts by specific tags
     $relatedPosts = Post::join('post_tags', 'posts.id', '=', 'post_tags.post_id')->join('tags', 'post_tags.tag_id', '=', 'tags.id')->whereIn('post_tags.tag_id', $postTagIds)->orderByRaw('RAND()')->take(10)->select('posts.*', 'tags.name as tagName')->take(3)->distinct()->get();
     return view('property', compact('post', 'relatedPosts'));
 }
Example #9
0
<?php

// Admin routes
Route::group(['prefix' => 'admin', 'middleware' => 'admin-auth', 'namespace' => 'Xadmin\\Controllers'], function () {
    Route::get('/', ['as' => 'admin.root', 'uses' => 'DashboardController@index']);
    // 'root' is route name used to make the application index url separate from the rest of the pages and routes.
    Route::resource('pages', 'PageController');
    Route::resource('posts', 'PostController');
    Route::resource('files', 'FileController');
    Route::resource('menu', 'MenuController');
    Route::resource('users', 'UserController');
    Route::resource('tags', 'TagController');
    Route::get('post-media', ['as' => 'admin.post-media.index', 'uses' => 'PostController@postMedia']);
    Route::post('post-media-store', ['as' => 'admin.post-media.store', 'uses' => 'PostController@storePostMedia']);
});
// Admin Public Routes
Route::group(['prefix' => 'admin', 'namespace' => 'Xadmin\\Controllers'], function () {
    // Authentication
    Route::get('login', ['as' => 'admin.auth.login', 'uses' => 'AuthController@getLogin']);
    Route::post('login', ['as' => 'admin.auth.login', 'uses' => 'AuthController@postLogin']);
    Route::get('logout', ['as' => 'admin.auth.logout', 'uses' => 'AuthController@getLogout']);
});
Route::get('test', function () {
    $posts = \Xadmin\Models\Post::get();
    foreach ($posts as $key => $post) {
        $post->slug = str_slug($post->title);
        $post->save();
    }
});
Example #10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::where('id', $id)->where('post_type', 'page')->first();
     if ($post && $post->delete) {
         return redirect()->back()->with('message', 'Deleted Successfully.');
     }
     return redirect()->back()->with('message', 'Unable to delete.');
 }