1

I'm doing a simple search in my view for some registered videos, this search returns the videos searchable through the post on the form.

The problem happens in the return of data, it does not update the page with the array passed to the view.

This is my form:

<form action="{{ URL::to("/search-video") }}" method="POST" accept-charset="utf-8" class="formSend BuscarVideoSend" id="form-busca-video">

    <div class="col l10">

        <input placeholder="Searchvídeo" name="Name" type="text" class="validate input-white Name valid">    
    </div>
    <div class="col l2">
        <button type="submit" class="btnSend" > Search</button> 
    </div>

</form>

Controller:

public function searchVideo(Request $request){
    $data = $request->all();

    $videos = TbVideoModel::where(
        'nm_video', 
        'LIKE', 
        '%'.$data['Name'].'%'
    )->get();


    return view('layouts.videos', compact('videos', $videos));
}

Html to return:

<section id="videoMosaic">
    <div class="row "> 
        <ul>

            @if(isset($videos))
                @foreach($videos as $video)
                <li>
                    <a class="bla-1" href="{{$video->ds_link}}">
                        <div class="div-imagem-texto">
                            <img src="http://img.youtube.com/vi/{{$video['ds_imagem_video']}}/0.jpg" alt="">
                            <div class="texto-sobre-imagem">
                                <img src="/images/play.png" alt="" class="play">
                                {{$video->nm_video}}
                                <p>{{$video->tx_video}}</p>

                            </div>                        
                        </div>
                    </a> 
                </li>
                @endforeach
            @endif
        </ul>

    </div>
</section>

It returns the data correctly on console xhr, but it has this error:

Uncaught SyntaxError: Unexpected token <

What do I need for the page to be updated with search data? Tks

3
  • 2
    What's the XHR response? Looks like there's invalid JS(ON) in there. Commented Apr 17, 2016 at 18:04
  • @Rudie the xhr contains what the page should display Commented Apr 17, 2016 at 18:07
  • In which line you're getting Syntax error. Commented Apr 17, 2016 at 18:36

1 Answer 1

1

There error is in your compact function:

return view('layouts.videos', compact('videos'));

PHP Docs on compact()

Sign up to request clarification or add additional context in comments.

3 Comments

thank you for the answer, but it is not only what is wrong, the problem remains.
@let try to run dd($videos) before your return statement to see if the data was properly loaded from the DB.
Thank you all, the error was actually in ajax. In the form it has some classes to make the ajax, but for this post was not using and it caused conflict. Once I removed the classes with ajax calls and modified the compact () function like @Dov says, worked properly.

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.