ddimonn8080
@ddimonn8080

Почему ошибка об отсутствии класса в Laravel?

Здравствуйте. Установил
laravel-jsvalidation

Все сделал как здесь потом
еще
composer dump-autoload

в view подключил как в примере
то есть так:
<!-- Laravel Javascript Validation -->
<script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('App\Http\Requests\MyFormRequest') !!}

resources/views/layouts/admin.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Админ панель</title>
    <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/dashboard/">

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="{{ URL::to('css/bootstrap-min.css') }}">

    <!-- Alertyfy CSS -->
    <link rel="stylesheet" href="{{ URL::to('plugins/alertyfy/themes/alertify.core.css') }}">
    <link rel="stylesheet" href="{{ URL::to('plugins/alertyfy/themes/alertify.default.css') }}">
    <link rel="stylesheet" href="{{ URL::to('plugins/alertyfy/themes/alertify.bootstrap.css') }}">

    <!-- Custom styles for this template -->
    <link href="/css/dashboard.css" rel="stylesheet">
</head>

<body>
<nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
    <button class="navbar-toggler navbar-toggler-right hidden-lg-up" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="/admin">Панель управления</a>

    <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="/admin">Главная <span class="sr-only">(current)</span></a>
            </li>
        </ul>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <nav class="col-sm-3 col-md-2 hidden-xs-down bg-faded sidebar">
            <ul class="nav nav-pills flex-column">
                <li class="nav-item">
                    <a class="nav-link {{ active(['admin.products', 'admin.products.*', 'not:admin.products.categories', 'not:admin.products.categories.*']) }}" href="{!! route('admin.products') !!}">Товары</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {{ active(['admin.products.categories', 'admin.products.categories.*']) }}" href="{!! route('admin.products.categories') !!}">Категории товаров <span class="sr-only">(current)</span></a>
                </li>
            </ul>
        </nav>

        @yield('content')
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{{ URL::to('js/custom-js/jquery-3.2.1.js') }}"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="{{ URL::to('plugins/alertyfy/lib/alertify.js') }}"></script>

<script src="{{ URL::to('plugins/tinymce/tinymce.min.js') }}"></script>
<script src="{{ URL::to('js/custom-js/tiny-mce-init-admin.js') }}"></script>

{{--<script src="{{ URL::to('plugins/jquery-validation/jquery.validate.min.js') }}"></script>
<script src="{{ URL::to('js/custom-js/init-admin.js') }}"></script>--}}

<!-- Laravel Javascript Validation -->
<script type="text/javascript" src="{{ url('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('App/Http/Requests/ProductsRequest') !!}

@yield('js')

@include('inc.messages')
</body>
</html>

app/Http/Requests/ProductsRequest.php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ProductsRequest extends FormRequest
{
    public function rules()
    {
        return [
            'title' => 'required|string|min:4|max:25',
            'slug' => array(
                'required',
                'string',
                'min:4',
                'max:25',
                'regex:/^[a-z0-9а-яё-]+$/u',
                Rule::unique('products')->ignore($this->id),
            ),
            'excerpt' => 'required|string|min:4|max:100',
            'content' => 'required|string|min:4|max:300',
            'descrtitle' => 'required|string|min:4|max:100',
            'descrtext' => 'required|string|min:4|max:300',
            'descr' => 'required|string|min:4|max:300',
            'regular_price' => [
                'required',
                'regex:/\d+/',
            ],
            'sale_price' => '',
            'discount' => [
                'required',
                'min:0',
                'max:100',
                'regex:/^\d+(\.\d{1,2})?$/',
            ],
            'currency' => 'string',
            'image' => 'mimes:jpeg,jpg,png,gif|max:10000',
            'tab_bg' => 'mimes:jpeg,jpg,png,gif|max:10000',
            'product_description_tab_content' => 'max:10000',
            'product_ingredients_tab_content' => 'max:10000',
            'product_usage_tab_content' => 'max:10000',
            'is_reccomended' => '',
        ];
    }
}

При этом дает ошибку
ErrorException (E_ERROR)
Class App/Http/Requests/ProductsRequest does not exist (View: D:\react\laravel-react\resources\views\layouts\admin.blade.php) (View: D:\react\laravel-react\resources\views\layouts\admin.blade.php)


Я что-то забыл? Где я ошибся?
Спасибо.
  • Вопрос задан
  • 135 просмотров
Решения вопроса 1
Maksclub
@Maksclub
maksfedorov.ru
{!! JsValidator::formRequest('App/Http/Requests/ProductsRequest') !!}

Неймспейсы пишутся с обратным слешем:
App\Http\Requests\ProductsRequest
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы