Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.2: Section-Include throws error #126

Closed
ghost opened this issue Jan 12, 2016 · 9 comments
Closed

Laravel 5.2: Section-Include throws error #126

ghost opened this issue Jan 12, 2016 · 9 comments

Comments

@ghost
Copy link

ghost commented Jan 12, 2016

Hello,

I try to use the following code:

@section('jsvalidator')
<script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('App\Http\Requests\FontUploadRequest') !!}
@stop

This section is in an template and include master template.
When i put this directly in master template all works correctly.

This results in the following error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Method Proengsoft\JsValidation\Manager::__toString() must not throw an exception

I use currently the newest version.

Can u help ?

@torrentalle
Copy link
Member

Hi,
can you post your 'App\Http\Requests\FontUploadRequest' ?

@ghost
Copy link
Author

ghost commented Jan 12, 2016

Hi,

here is it:

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class FontUploadRequest extends Request
{
/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'font_name' => 'required',
        'font_normal' => 'mimes:ttf',
        'font_bold' => 'mimes:ttf',
        'font_italic' => 'mimes:ttf',
        'font_bolditalic' => 'mimes:ttf'
    ];
}

public function attributes() {
    return [
        'font_name' => _('Schriftname'),
        'font_normal' => _('Normal'),
        'font_bold' => _('Bold'),
        'font_italic' => _('Italic'),
        'font_bolditalic' => _('Bold & Italic'),
    ];
}
}

Thanks.

@torrentalle
Copy link
Member

Hi
I can't reproduce your error. I think that your are not using latest version (1.3.1).
The class Proengsoft\JsValidation\Manager was removed in release 1.3.0

Check your composer.json file, it shlould be like this.

{
    "require": {
        "laravel/framework": "5.2.*",
        ...
        "proengsoft/laravel-jsvalidation": "~1.1"
    },
    ...
    "scripts": {
        "post-update-cmd": [
            ....
            "php artisan vendor:publish --provider=\"Proengsoft\\JsValidation\\JsValidationServiceProvider\" --tag=public --force"
        ],
    },
}

then run

$ composer update

@torrentalle
Copy link
Member

Hi,
I have tested your code with:

  • Laravel 5.1, JsValidation master
  • Laravel 5.2, JsValidation 1.3.1

In all case is working.

I took a look into your fork and it seems ok.

This is my test views.

template-master.blade.php

@extends('app')
@include('template-jsvalidator')

@section('content')
    <form> 
      <!-- ....... -->
    </form>
    @yield('jsvalidator')

@endsection

template-jsvalidator.blade.php

@section('jsvalidator')
<script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! \JsValidator::formRequest('App\Http\Requests\FontUploadRequest') !!}
@stop

@ghost
Copy link
Author

ghost commented Jan 13, 2016

Hello,

I make a cleanup.

Now I get the following error:

Method Proengsoft\JsValidation\Javascript\JavascriptValidator::__toString() must not throw an exception

In your example you have a depth of 2 views. I have more then two. Currently my views are so:

master.blade.php

 <script type="text/javascript" src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
 @yield('jsvalidator');

configurator.blade.php

@extends('master')
@include('font_upload_button');

font_upload_button.blade.php

<div>
HTML-CODE, no SECTION
</div>
@section('jsvalidator')
    {!! \JsValidator::formRequest('App\Http\Requests\FontUploadRequest') !!}
@stop

With this markup I get the error

Method Proengsoft\JsValidation\Javascript\JavascriptValidator::__toString() must not throw an exception 

This error is in file font_upload_button.blade.php

Can u help ?

@ghost
Copy link
Author

ghost commented Jan 13, 2016

I use my fork, which is based on your current master.

I tested it to put it in master, but i get the same error.

@ghost
Copy link
Author

ghost commented Jan 13, 2016

Hello,

all is okay, I have a writing mistake in config for view path.

Can u make here a better error message ? For example view not found or so ?

Thanks for help!

@torrentalle
Copy link
Member

Hi,

If the view is rendered using __toString()magic method you cannot throw an exception from within a __toString().

A quick solution for debugging is to use render() method tho generate Javascript Validations. In this case the exceptions are thrown as usual.

JsValidator::formRequest('App\Http\Requests\FontUploadRequest')->render()

Now I'm looking how to render instead of throw the Exceptions in __toString method.

@torrentalle
Copy link
Member

This is fixed in dev-master branch. Now when Exception occurs in Jascacript Rendering, is converted to Error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant