/**
  * Blog post create form processing.
  *
  * @return Redirect
  */
 public function postCreate()
 {
     // Declare the rules for the form validation
     $rules = array('title' => 'required|min:3', 'content' => 'required|min:3');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Create a new blog post
         $post = new Post();
         // Update the blog post data
         $post->title = Input::get('title');
         $post->slug = convert_to_slug(Input::get('title'));
         $post->content = Input::get('content');
         $post->meta_title = Input::get('meta-title');
         $post->meta_description = Input::get('meta-description');
         $post->meta_keywords = Input::get('meta-keywords');
         $post->user_id = Sentry::getId();
         // Was the blog post created?
         if ($post->save()) {
             // Redirect to the new blog post page
             return Redirect::to('admin/blogs/' . $post->id . '/edit')->with('success', Lang::get('admin/blogs/messages.create.success'));
         }
         // Redirect to the blog post create page
         return Redirect::to('admin/blogs/create')->with('error', Lang::get('admin/blogs/messages.create.error'));
     }
     // Form validation failed
     return Redirect::to('admin/blogs/create')->withInput()->withErrors($validator);
 }
示例#2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Declare the rules for the form validation
     $rules = array('title' => 'required|min:3', 'content' => 'required|min:3|not_in:<p></p>', 'image' => 'image|max:30000000');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     // Create a new portfolio post
     $post = new PortfolioPost();
     // Update the portfolio post data
     $post->title = e(Input::get('title'));
     if (empty($post->slug)) {
         $post->slug = e(Str::slug(Input::get('title')));
     } else {
         $post->slug = e(Str::slug(Input::get('slug')));
     }
     $post->content = e(Input::get('content'));
     $post->draft = e(Input::get('draft'));
     $post->lang = e(Input::get('lang'));
     $post->content = e(Input::get('content'));
     $post->meta_title = e(Input::get('meta-title'));
     $post->meta_description = e(Input::get('meta-description'));
     $post->meta_keywords = e(Input::get('meta-keywords'));
     $post->user_id = Sentry::getId();
     $image = Input::file('image');
     if (!empty($image)) {
         $filename = $post->slug . '_' . date('d-m-Y') . '.' . $image->getClientOriginalExtension();
         $uploadSuccess = Input::file('image')->move($this->destinationPath, $filename);
         $post->image = e($filename);
     }
     // Was the portfolio post created?
     if ($post->save()) {
         $tags = explode(',', Input::get('portfoliotags'));
         foreach ($tags as $tag) {
             if (PortfolioTag::where('name', '=', $tag)->count() == 0) {
                 $newTag = new PortfolioTag();
                 $newTag->name = ucwords($tag);
                 $newTag->slug = Str::slug($tag);
                 $newTag->save();
             } else {
                 $newTag = PortfolioTag::where('name', '=', $tag)->first();
             }
             $post->tags()->attach($newTag->id);
         }
         // Redirect to the new portfolio post page
         return Redirect::route('portfolio.show', array('portfolio' => $post->slug))->with('success', Lang::get('modules/portfolio/messages.success.create'));
     }
     // Redirect to the portfolio post create page
     return Redirect::route('portfolio.create')->with('error', Lang::get('modules/portfolio/messages.error.create'));
 }
示例#3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Declare the rules for the form validation
     $rules = array('title' => 'required|min:3', 'content' => 'required|min:3|not_in:<p></p>');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     // Create a new page
     $page = new Page();
     // Update the page data
     $page->title = e(Input::get('title'));
     if (empty($page->slug)) {
         $page->slug = e(Str::slug(Input::get('title')));
     } else {
         $page->slug = e(Str::slug(Input::get('slug')));
     }
     $page->content = e(Input::get('content'));
     $page->draft = e(Input::get('draft'));
     $page->in_menu = e(Input::get('in_menu'));
     $page->lang = e(Input::get('lang'));
     $page->content = e(Input::get('content'));
     $page->meta_title = e(Input::get('meta-title'));
     $page->meta_description = e(Input::get('meta-description'));
     $page->meta_keywords = e(Input::get('meta-keywords'));
     $page->user_id = Sentry::getId();
     // Was the page created?
     if ($page->save()) {
         // Redirect to the new page page
         return Redirect::route('page.show', array('slug' => $page->slug))->with('success', Lang::get('modules/page/messages.success.create'));
     }
     // Redirect to the page create page
     return Redirect::route('page.create')->with('error', Lang::get('modules/page/messages.error.create'));
 }
 /**
  * Delete the given user, beware that the logged in user
  * can't be deleted, makes sense, right?
  *
  * @param  int  $userId
  * @return Redirect
  */
 public function getDelete($userId = null)
 {
     try {
         // Get user information
         $user = Sentry::getUserProvider()->findById($userId);
         // Check if we are not trying to delete ourselves
         if ($user->id === Sentry::getId()) {
             // Redirect to the user management page
             return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.impossible'));
         }
         // Was the user deleted?
         if ($user->delete()) {
             // Redirect to the user management page
             return Redirect::to('admin/users')->with('success', Lang::get('admin/users/messages.delete.success'));
         }
         // There was a problem deleting the user
         return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.delete.error'));
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         // Redirect to the user management page
         return Redirect::to('admin/users')->with('error', Lang::get('admin/users/messages.not_found'));
     }
 }
 /**
  * Delete the given user.
  *
  * @param  int  $id
  * @return Redirect
  */
 public function getDelete($id = null)
 {
     try {
         // Get user information
         $user = Sentry::getUserProvider()->findById($id);
         // Check if we are not trying to delete ourselves
         if ($user->id === Sentry::getId()) {
             // Prepare the error message
             $error = Lang::get('admin/users/message.error.delete');
             // Redirect to the user management page
             return Redirect::route('users')->with('error', $error);
         }
         // Do we have permission to delete this user?
         if ($user->isSuperUser() and !Sentry::getUser()->isSuperUser()) {
             // Redirect to the user management page
             return Redirect::route('users')->with('error', 'Insufficient permissions!');
         }
         // Delete the user
         $user->delete();
         // Prepare the success message
         $success = Lang::get('admin/users/message.success.delete');
         // Redirect to the user management page
         return Redirect::route('users')->with('success', $success);
     } catch (UserNotFoundException $e) {
         // Prepare the error message
         $error = Lang::get('admin/users/message.user_not_found', compact('id'));
         // Redirect to the user management page
         return Redirect::route('users')->with('error', $error);
     }
 }