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

use App\Http\Requests\SavePostRequest;
use Carbon\Carbon;
use Illuminate\Auth\Guard;
use Illuminate\Http\Request;

use Cocur\Slugify\Slugify;

use App\Http\Controllers\Controller;
use App\Model\Post;

class NewsController extends Controller
{
  public function index(Request $request)
  {
    $order = $request->input('order_by', 'created_at');

    $posts = Post::with('author')->orderBy($order)->paginate(15);

    return view('admin.news.index', [
      'posts' => $posts,
      'order' => $order
    ]);
  }

  public function create()
  {
    return view('admin.news.edit', ['post' => (new Post)->newInstance()]);
  }

  public function edit($id)
  {
    return view('admin.news.edit', ['post' => Post::findOrFail($id)]);
  }

  public function slug(Slugify $slugify, Request $request)
  {
    return response()->json(['slug' => $slugify->slugify($request->input('title'))]);
  }

  public function save(SavePostRequest $request, Guard $guard)
  {
    $postData = $request->except(['_token', 'id']);

    if ($postData['published_at'] === '')<commit_msg>Changed default sorting for admin post listing<commit_after><?php namespace App\Http\Controllers\Admin;

use App\Http\Requests\SavePostRequest;
use Carbon\Carbon;
use Illuminate\Auth\Guard;
use Illuminate\Http\Request;

use Cocur\Slugify\Slugify;

use App\Http\Controllers\Controller;
use App\Model\Post;

class NewsController extends Controller
{
  public function index(Request $request)
  {
    $order = $request->input('order_by', 'created_at');

    // TODO: introduce sorting option
    $sort  = ($order === 'created_at') ? 'desc' : 'asc';

    $posts = Post::with('author')->orderBy($order, $sort)->paginate(15);

    return view('admin.news.index', [
      'posts' => $posts,
      'order' => $order
    ]);
  }

  public function create()
  {
    return view('admin.news.edit', ['post' => (new Post)->newInstance()]);
  }

  public function edit($id)
  {
    return view('admin.news.edit', ['post' => Post::findOrFail($id)]);
  }

  public function slug(Slugify $slugify, Request $request)
  {
    return response()->json(['slug' => $slugify->slugify($request->input('title'))]);
  }

  public function save(SavePostRequest $request, Guard $guard)
  {
    $postData = $request->except(['_token', 'id']);

    if ($postData['published_at'] === '')
{'fraction_non_alphanumeric': 0.17944397641112048, 'fraction_numerical': 0.0016849199663016006, 'mean_word_length': 4.208333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '3861082', 'n_tokens_mistral': 773, 'n_tokens_neox': 773, 'n_words': 158}