<commit_before><?php namespace Strimoid\Providers;

use Hashids;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Strimoid\Models\Comment;
use Strimoid\Models\CommentReply;
use Strimoid\Models\Content;
use Strimoid\Models\ContentRelated;
use Strimoid\Models\Conversation;
use Strimoid\Models\Entry;
use Strimoid\Models\EntryReply;
use Strimoid\Models\Group;
use Strimoid\Models\Notification;
use Strimoid\Models\User;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to the controller routes in your routes file.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'Strimoid\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param \Illuminate\Routing\Router $router
     *
     * @return void
     */
    public function boot(Router $router)
    {
        $this->bindModel($router, 'content', Content::class);
        $this->bindModel($router, 'related', ContentRelated::class);
        $this->bindModel($router, 'notification', Notification::class);
        $this->bindModel($router, 'comment', Comment::class);
        $this->bindModel($router, 'comment_reply', CommentReply::class);
        $this->bindModel($router, 'entry', Entry::class);
        $this->bindModel($router, 'entry_reply', EntryReply::class);
        $this->bindModel($router, 'group', Group::class);
        $this->bindModel($router, 'user', User::class);
        $this->bindModel($router, 'conversation', Conversation::class);

        parent::boot($router);
    }

    /**
     * Bind object resolve function for given model class.
     *
     * @param Router $router
     * @param $key
     * @param $className
     */
    public function bindModel(Router $router, $key, $className)
    {
        $router->bind($key, function($value, $route) use($className) {
            if (ends_with($className, ['Group', 'User'])) {
                return $className::name($value)->firstOrFail();
            }

            $ids = Hashids::decode($value);

            if (!count($ids)) {
                abort(404);
            }

            return $className::findOrFail($ids[0]);
        });
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->loadRoutesFrom(app_path('Http/routes.php'));
    }
}<commit_msg>throwing 404 exception when no entry or any other model<commit_after><?php namespace Strimoid\Providers;

use Hashids;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Strimoid\Models\Comment;
use Strimoid\Models\CommentReply;
use Strimoid\Models\Content;
use Strimoid\Models\ContentRelated;
use Strimoid\Models\Conversation;
use Strimoid\Models\Entry;
use Strimoid\Models\EntryReply;
use Strimoid\Models\Group;
use Strimoid\Models\Notification;
use Strimoid\Models\User;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to the controller routes in your routes file.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'Strimoid\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param \Illuminate\Routing\Router $router
     *
     * @return void
     */
    public function boot(Router $router)
    {
        $this->bindModel($router, 'content', Content::class);
        $this->bindModel($router, 'related', ContentRelated::class);
        $this->bindModel($router, 'notification', Notification::class);
        $this->bindModel($router, 'comment', Comment::class);
        $this->bindModel($router, 'comment_reply', CommentReply::class);
        $this->bindModel($router, 'entry', Entry::class);
        $this->bindModel($router, 'entry_reply', EntryReply::class);
        $this->bindModel($router, 'group', Group::class);
        $this->bindModel($router, 'user', User::class);
        $this->bindModel($router, 'conversation', Conversation::class);

        parent::boot($router);
    }

    /**
     * Bind object resolve function for given model class.
     *
     * @param Router $router
     * @param $key
     * @param $className
     */
    public function bindModel(Router $router, $key, $className)
    {
        $router->bind($key, function($value, $route) use($className) {
            if (ends_with($className, ['Group', 'User'])) {
                try {
                    return $className::name($value)->firstOrFail();
                } catch (ModelNotFoundException $e ) {
                    throw new NotFoundHttpException;
                }
            }

            $ids = Hashids::decode($value);

            if (!count($ids)) {
                abort(404);
            }
            try {
                return $className::findOrFail($ids[0]);
            } catch (ModelNotFoundException $e ) {
                throw new NotFoundHttpException;
            }
           
        });
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->loadRoutesFrom(app_path('Http/routes.php'));
    }
}
{'fraction_non_alphanumeric': 0.13243486073674754, 'fraction_numerical': 0.001976639712488769, 'mean_word_length': 2.723076923076923, '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': '2541539', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1557, 'n_words': 351}