<commit_before><?php namespace App\Http\Controllers\Admin;

use App\Category;
use App\Http\Controllers\Controller;
use App\Http\Requests\AdminPostRequest;
use App\Post;
use App\Tag;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Laracasts\Flash\Flash;

class PostController extends Controller {

	/**
	 * Display a listing of the resource.
	 * GET /adminposts
	 *
	 * @return Response
	 */
	public function index()
	{
		$posts = Post::all();
		return view('admin.post.index')
			->with('posts', $posts);
	}

	/**
	 * Show the form for creating a new resource.
	 * GET /adminposts/create
	 *
	 * @return Response
	 */
	public function create()
	{
		$categories = Category::all();
		$tags = Tag::groupBy('name')->lists('name');
		return view('admin.post.create')
			->with('tags', json_encode($tags))
			->with('categories', $categories);
	}

	/**
	 * Store a newly created resource in storage.
	 * POST /adminposts
	 *
	 * @return Response
	 */
	public function store(AdminPostRequest $request)
	{

		$post = new Post;
		$post->user_id = Auth::id();
		$post->title = Request::get('title');
		$post->content = Request::get('content');
		$post->status = Request::get('status');
		$post->allow_comments = Request::get('allow_comments');
		$post->created_at = Request::get('created_at');

		// IMAGE BANNER
		if (Request::hasFile('image')) {
			$file            = Request::file('image');
			$destinationPath = public_path().'/uploads/';
			$filename 		 = str_random(6) . '_image_' . $file->getClientOriginalName();
			$uploadSuccess   = $file->move($destinationPath, $filename);
			$post->image = $filename;
		}
		$post->save();

		// Clear previous tags
		$current_tags = $post->tags()->delete();
		$tags = Request::get('tags');
		if (count($tags)) {
			foreach ($tags as $tag) {
				$new_tag = new Tag;
				$new_tag->name = $tag;
				$post->tags()->save($new_tag);
			}
		}
		
		$post->categories()->sync(Request::get('category_id'));

		return Redirect::route('admin.post.index');
	}

	/**
	 * Display the specified resource.
	 * GET /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 * GET /adminposts/{id}/edit
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		$post = Post::find($id);
		$categories = Category::all();
		$tags = Tag::groupBy('name')->lists('name');
		return view('admin.post.edit')
			->with('post', $post)
			->with('tags', json_encode($tags))
			->with('categories', $categories);
	}

	/**
	 * Update the specified resource in storage.
	 * PUT /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update(AdminPostRequest $request, $id)
	{

		$post = Post::find($id);
		$post->title = Request::get('title');
		$post->content = Request::get('content');
		$post->status = Request::get('status');
		$post->allow_comments = Request::get('allow_comments');
		$post->created_at = Request::get('created_at');

		// IMAGE BANNER
		if (Request::hasFile('image')) {
			$file            = Request::file('image');
			$destinationPath = public_path().'/uploads/';
			$filename 		 = str_random(6) . '_image_' . $file->getClientOriginalName();
			$uploadSuccess   = $file->move($destinationPath, $filename);
		}
		else {
			$filename = $post->image;
		}

		$post->image = $filename;
		$post->save();

		// Clear previous tags
		$current_tags = $post->tags()->delete();
		$tags = Request::get('tags');
		if (count($tags)) {
			foreach ($tags as $tag) {
				$new_tag = new Tag;
				$new_tag->name = $tag;
				$post->tags()->save($new_tag);
			}
		}

		$post->categories()->sync(Request::get('category_id'));

		Flash::success('Post edited !');

		return Redirect::back();
	}

	/**
	 * Remove the specified resource from storage.
	 * DELETE /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		$post = Post::find($id);
		$post->delete();
		return Redirect::route('admin.post.index');
	}

}<commit_msg>avoid problem with spaces in image name<commit_after><?php namespace App\Http\Controllers\Admin;

use App\Category;
use App\Http\Controllers\Controller;
use App\Http\Requests\AdminPostRequest;
use App\Post;
use App\Tag;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Laracasts\Flash\Flash;

class PostController extends Controller {

	/**
	 * Display a listing of the resource.
	 * GET /adminposts
	 *
	 * @return Response
	 */
	public function index()
	{
		$posts = Post::all();
		return view('admin.post.index')
			->with('posts', $posts);
	}

	/**
	 * Show the form for creating a new resource.
	 * GET /adminposts/create
	 *
	 * @return Response
	 */
	public function create()
	{
		$categories = Category::all();
		$tags = Tag::groupBy('name')->lists('name');
		return view('admin.post.create')
			->with('tags', json_encode($tags))
			->with('categories', $categories);
	}

	/**
	 * Store a newly created resource in storage.
	 * POST /adminposts
	 *
	 * @return Response
	 */
	public function store(AdminPostRequest $request)
	{

		$post = new Post;
		$post->user_id = Auth::id();
		$post->title = Request::get('title');
		$post->content = Request::get('content');
		$post->status = Request::get('status');
		$post->allow_comments = Request::get('allow_comments');
		$post->created_at = Request::get('created_at');

		// IMAGE BANNER
		if (Request::hasFile('image')) {
			$file            = Request::file('image');
			$destinationPath = public_path().'/uploads/';
			$filename 		 = urlencode(str_random(6) . '_image_' . $file->getClientOriginalName());
			$uploadSuccess   = $file->move($destinationPath, $filename);
			$post->image = $filename;
		}
		$post->save();

		// Clear previous tags
		$current_tags = $post->tags()->delete();
		$tags = Request::get('tags');
		if (count($tags)) {
			foreach ($tags as $tag) {
				$new_tag = new Tag;
				$new_tag->name = $tag;
				$post->tags()->save($new_tag);
			}
		}
		
		$post->categories()->sync(Request::get('category_id'));

		return Redirect::route('admin.post.index');
	}

	/**
	 * Display the specified resource.
	 * GET /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 * GET /adminposts/{id}/edit
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		$post = Post::find($id);
		$categories = Category::all();
		$tags = Tag::groupBy('name')->lists('name');
		return view('admin.post.edit')
			->with('post', $post)
			->with('tags', json_encode($tags))
			->with('categories', $categories);
	}

	/**
	 * Update the specified resource in storage.
	 * PUT /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update(AdminPostRequest $request, $id)
	{

		$post = Post::find($id);
		$post->title = Request::get('title');
		$post->content = Request::get('content');
		$post->status = Request::get('status');
		$post->allow_comments = Request::get('allow_comments');
		$post->created_at = Request::get('created_at');

		// IMAGE BANNER
		if (Request::hasFile('image')) {
			$file            = Request::file('image');
			$destinationPath = public_path().'/uploads/';
			$filename 		 = urlencode(str_random(6) . '_image_' . $file->getClientOriginalName());
			$uploadSuccess   = $file->move($destinationPath, $filename);
		}
		else {
			$filename = $post->image;
		}

		$post->image = $filename;
		$post->save();

		// Clear previous tags
		$current_tags = $post->tags()->delete();
		$tags = Request::get('tags');
		if (count($tags)) {
			foreach ($tags as $tag) {
				$new_tag = new Tag;
				$new_tag->name = $tag;
				$post->tags()->save($new_tag);
			}
		}

		$post->categories()->sync(Request::get('category_id'));

		Flash::success('Post edited !');

		return Redirect::back();
	}

	/**
	 * Remove the specified resource from storage.
	 * DELETE /adminposts/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		$post = Post::find($id);
		$post->delete();
		return Redirect::route('admin.post.index');
	}

}
{'fraction_non_alphanumeric': 0.18973862536302033, 'fraction_numerical': 0.000484027105517909, 'mean_word_length': 3.6095928611266035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945039', 'n_tokens_mistral': 3042, 'n_tokens_neox': 2699, 'n_words': 568}