<commit_before><?php

namespace Yajra\CMS\Http\Controllers;

use Nwidart\Modules\Repository;
use Yajra\CMS\DataTables\ModulesDataTable;

class ModulesController extends Controller
{
    /**
     * @var \Nwidart\Modules\Repository
     */
    protected $modules;

    /**
     * ModulesController constructor.
     *
     * @param \Nwidart\Modules\Repository $modules
     */
    public function __construct(Repository $modules)
    {
        $this->modules = $modules;
        $this->authorizePermissionResource('module');
    }

    /**
     * Display list of modules.
     *
     * @param \Yajra\CMS\DataTables\ModulesDataTable $dataTable
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function index(ModulesDataTable $dataTable)
    {
        return $dataTable->render('administrator.modules.index');
    }

    /**
     * @param string $module
     * @return \Illuminate\View\View
     */
    public function show($module)
    {
        return view('administrator.modules.profile', compact('module'));
    }

    /**
     * Remove selected module.
     *
     * @param string $module
     * @return \Illuminate\Http\JsonResponse
     * @throws \Exception
     */
    public function destroy($module)
    {
        /** @var \Nwidart\Modules\Module $module */
        $module = $this->modules->find($module);
        $module->delete();

        return $this->notifySuccess(trans('cms::module.destroy', ['module' => (string) $module]));
    }

    /**
     * Toggle module active status.
     *
     * @param string $module
     * @return \Illuminate\Http\JsonResponse
     */
    public function toggle($module)
    {
        /** @var \Nwidart\Modules\Module $module */
        $module = $this->modules->find($module);

        if ($module->disabled()) {
            $module->enable();
        } else {
            $module->disable();
        }

        $message = 'cms::module.toggle.' . ($module->enabled() ? 'enable' : 'disable');

        return $this->notifySuccess(trans($message, ['module' => (string) $module]));
    }
}
<commit_msg>Fix toggling of module by alias.<commit_after><?php

namespace Yajra\CMS\Http\Controllers;

use Nwidart\Modules\Repository;
use Yajra\CMS\DataTables\ModulesDataTable;

class ModulesController extends Controller
{
    /**
     * @var \Nwidart\Modules\Repository
     */
    protected $modules;

    /**
     * ModulesController constructor.
     *
     * @param \Nwidart\Modules\Repository $modules
     */
    public function __construct(Repository $modules)
    {
        $this->modules = $modules;
        $this->authorizePermissionResource('module');
    }

    /**
     * Display list of modules.
     *
     * @param \Yajra\CMS\DataTables\ModulesDataTable $dataTable
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
     */
    public function index(ModulesDataTable $dataTable)
    {
        return $dataTable->render('administrator.modules.index');
    }

    /**
     * @param string $module
     * @return \Illuminate\View\View
     */
    public function show($module)
    {
        return view('administrator.modules.profile', compact('module'));
    }

    /**
     * Remove selected module.
     *
     * @param string $module
     * @return \Illuminate\Http\JsonResponse
     * @throws \Exception
     */
    public function destroy($module)
    {
        /** @var \Nwidart\Modules\Module $module */
        $module = $this->modules->find($module);
        $module->delete();

        return $this->notifySuccess(trans('cms::module.destroy', ['module' => (string) $module]));
    }

    /**
     * Toggle module active status.
     *
     * @param string $module
     * @return \Illuminate\Http\JsonResponse
     */
    public function toggle($module)
    {
        /** @var \Nwidart\Modules\Module $module */
        $module = $this->modules->findByAlias($module);

        if ($module->disabled()) {
            $module->enable();
        } else {
            $module->disable();
        }

        $message = 'cms::module.toggle.' . ($module->enabled() ? 'enable' : 'disable');

        return $this->notifySuccess(trans($message, ['module' => (string) $module]));
    }
}

{'fraction_non_alphanumeric': 0.1496420047732697, 'fraction_numerical': 0.0, 'mean_word_length': 2.3608660785886126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '241066', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1223, 'n_words': 223}