1

My problem seems to be with Laravel helpers. Everything was working fine until I change some files to other folders, of course I changed the routes and on routes and controllers but now I'm getting this message:

ErrorException in HtmlBuilder.php line 65: htmlentities() expects parameter 1 to be string, array given (View: /Library/WebServer/Documents/gamstec/resources/views/posts/create.blade.php)

This is my create file:

<div class="content">
    <div class="container-fluid">
        <div class="row well bs-component">
            <div class="col-md-8 col-md-offset">
            <div class="input-group">

                <h3 class="text-center">Crear Nueva Publicación</h3>
                <hr>

                {!! Form::open(array('route' => 'posts.store', 'data-parsley-validate' => '')) !!}

                    {{ Form::label('title', ' Título:', array('class' => 'fa fa-pencil')) }}

                    {{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255')) }}

                    {{ Form::label('body', ' Contenido:', array('class' => 'fa fa-pencil-square-o')) }}

                    {{ Form::textarea('body', null, array('class' => 'form-control', 'required' => '')) }}

                    {{ Form::submit('Publicar', array('class' => 'btn btn-info')) }}


                </div>
            </div> <!-- col-md-8 end -->


            <div class="col-md-4">
            <div class="input-group">
                <h3 class="text-center">Categoría e imágen</h3>
                <hr>


                     <br> <hr>

                    {{ Form::label('badge', ' Etiqueta:', array('class' => 'fa fa-tags')) }}

                    {{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}
                    <br> <hr>

                     {{ Form::label('postimg', ' Seleccionar Imagen', array('class' => 'fa fa-picture-o')) }}
                    <br> <br>
                    {{ Form::file('postimg', array('require' => '', 'maxlength' => '255')) }}

                {!! Form::close() !!}

            </div> <!-- item-group end -->
            </div> <!-- col-md-4 end -->


        </div> <!-- end of row -->
    </div> <!-- end of container -->
</div> <!-- end of content -->

This is my controller file:

<?php


public function index()
{
    return view('admin');
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    return view('posts.create');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    // validate the data
    $this->validate($request, array(
        'title' => 'required|max:255',
        'body' => 'required',
        ));

    // store in database
    $post = new Post;

    $post->title = $request->title;
    $post->body = $request->body;
    $post->badge = $request->badge;
    $post->postimg = $request->postimg;

    $post->save();

    Session::flash('success', 'La publicación se ha creado correctamente');

    // redirect to another page
    return redirect()->route('show', $post->id);
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    $post = Post::find($id);
    return view('show')->withPost($post);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}

I'll be grateful for your help.

5
  • You didn't show HtmlBuilder.php line 65 but there is a call to htmlentities() there and you are passing an array to that. Commented Mar 9, 2017 at 20:53
  • sorry for that, this is the HtmlBuilder.php at line 65 public function escapeAll($value) { return htmlentities($value, ENT_QUOTES, 'UTF-8'); } Commented Mar 9, 2017 at 21:04
  • So you have to trace it. Something in your code calls something else that eventually calls escapeAll(). Before the htmlentities() use debug_print_backtrace() to see where it is coming from. Commented Mar 9, 2017 at 21:07
  • i'm new on this, can you tell me how can i use debug_print_backtrace() ? Commented Mar 9, 2017 at 21:12
  • Sorry, the parameter that system spected was null. finally running :D Commented Mar 9, 2017 at 21:57

2 Answers 2

2

That's line generate the error:

{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}

You can pass an additional value option as a second argument can't be an array

To add other attributes, pass a third argument to the method. This third argument must be an array.

Change to this :

{{ Form::text('badge', '', array('class' => 'form-control', 'maxlength' => '20')) }}
Sign up to request clarification or add additional context in comments.

2 Comments

try using old('badge') instead of just '' to prefill values if there is an error on the form
@JuanRincón If this answer solved your question, consider accepting it by clicking the outlined checkmark under the down arrow; this marks the question as 'solved' and awards the answerer who put time into solving your issue.
0

It's this line in your code:

{{ Form::text('badge', array('class' => 'form-control', 'maxlength' => '20')) }}

It needs null as the second value:

{{ Form::text('badge', null, array('class' => 'form-control', 'maxlength' => '20')) }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.